Skip to content

Commit

Permalink
Merge pull request #57 from serilog/dev
Browse files Browse the repository at this point in the history
2.0.0 Release
  • Loading branch information
nblumhardt authored Nov 9, 2023
2 parents b81d6f3 + 8082e56 commit 91be91b
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 80 deletions.
40 changes: 23 additions & 17 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
Write-Output "build: Build started"

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if(Test-Path .\artifacts) {
Write-Output "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore --no-cache
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"]
Write-Output "build: Package version suffix is $suffix"
Write-Output "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/Serilog.*) {
Push-Location $src
& dotnet build --configuration Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true

& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$suffix
if($LASTEXITCODE -ne 0) { exit 1 }
if($LASTEXITCODE -ne 0) { throw 'build failed' }

Pop-Location
if($suffix) {
& dotnet pack src\Serilog.Formatting.Compact --configuration Release --no-build --no-restore -o artifacts --version-suffix=$suffix
} else {
& dotnet pack src\Serilog.Formatting.Compact --configuration Release --no-build --no-restore -o artifacts
}

foreach ($test in ls test/Serilog.*.Tests) {
Push-Location $test
if($LASTEXITCODE -ne 0) { throw 'pack failed' }

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
Write-Output "build: Testing"

Pop-Location
}
& dotnet test test\Serilog.Formatting.Compact.Tests --configuration Release --no-build --no-restore

Pop-Location
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
supported targets: netstandard2.0, net6.0
updated packages in test proj
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,15 @@ See `test/Serilog.Formatting.Compact.Tests/FormattingBenchmarks.cs`.
|:------------------------------ |----------: |---------: |------: |
| `JsonFormatter` | 11.2775 µs | 0.0682 µs | 1.00 |
| `CompactJsonFormatter` | 6.0315 µs | 0.0429 µs | 0.53 |
| `RenderedJsonFormatter` | 13.7585 µs | 0.1194 µs | 1.22 |
| `JsonFormatter(renderMessage: true)` | 13.7585 µs | 0.1194 µs | 1.22 |
| `RenderedCompactJsonFormatter` | 7.0680 µs | 0.0605 µs | 0.63 |

### Tools

Several tools are available for working with the CLEF format.

* **[_Analogy.LogViewer.Serilog_](https://github.com/Analogy-LogViewer/Analogy.LogViewer.Serilog)** - CLEF parser for [Analogy Log Viewer](https://github.com/Analogy-LogViewer/Analogy.LogViewer)
* **[`clef-tool`](https://github.com/datalust/clef-tool)** - a CLI application for processing CLEF files
* **[Compact Log Format Viewer](https://github.com/warrenbuckley/Compact-Log-Format-Viewer)** - a cross-platform viewer for CLEF JSON files
* **[_Serilog.Formatting.Compact.Reader_](https://github.com/serilog/serilog-formatting-compact-reader)** - convert CLEF JSON documents back into Serilog `LogEvent`s

* **[Compact Log Format Viewer](https://github.com/warrenbuckley/Compact-Log-Format-Viewer)** - a cross-platform viewer for CLEF files
* **[`seqcli`](https://github.com/datalust/seqcli)** - pretty-`print` CLEF files at the command-line, or `ingest` CLEF files into [Seq](https://datalust.co/seq) for search, and analysis
* **[_Serilog.Formatting.Compact.Reader_](https://github.com/serilog/serilog-formatting-compact-reader)** - convert CLEF documents back into Serilog `LogEvent`s
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2019
image: Visual Studio 2022
configuration: Release
install:
- ps: ./Setup.ps1
build_script:
- ps: ./Build.ps1
test: off
test: false
artifacts:
- path: artifacts/Serilog.*.nupkg
deploy:
- provider: NuGet
api_key:
secure: ptRAVPZZO/hlZUv5e/yLnHF7aAh8tQmBfvLt64Qrvhoe7I/mbbPNI6RYm92g5EzG
secure: 4nUKbHgmKmedr6dDtCT2uWVLeQl+tFqO+y9LvRi3nk7cvD/DnOYI1ZqajsgDqxnH
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
Binary file added assets/serilog-extension-nuget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "7.0.304"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
// limitations under the License.

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Serilog.Events;
using Serilog.Formatting.Json;
using Serilog.Parsing;
// ReSharper disable MemberCanBePrivate.Global

namespace Serilog.Formatting.Compact
{
Expand Down Expand Up @@ -76,12 +78,12 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
{
output.Write(",\"@r\":[");
var delim = "";
foreach (var r in tokensWithFormat)
foreach (PropertyToken r in tokensWithFormat)
{
output.Write(delim);
delim = ",";
var space = new StringWriter();
r.Render(logEvent.Properties, space);
r.Render(logEvent.Properties, space, CultureInfo.InvariantCulture);
JsonValueFormatter.WriteQuotedJsonString(space.ToString(), output);
}
output.Write(']');
Expand All @@ -100,6 +102,20 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
JsonValueFormatter.WriteQuotedJsonString(logEvent.Exception.ToString(), output);
}

if (logEvent.TraceId != null)
{
output.Write(",\"@tr\":\"");
output.Write(logEvent.TraceId.Value.ToHexString());
output.Write('\"');
}

if (logEvent.SpanId != null)
{
output.Write(",\"@sp\":\"");
output.Write(logEvent.SpanId.Value.ToHexString());
output.Write('\"');
}

foreach (var property in logEvent.Properties)
{
var name = property.Key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.

using System;
using System.Globalization;
using System.IO;
using Serilog.Events;
using Serilog.Formatting.Json;
// ReSharper disable MemberCanBePrivate.Global

namespace Serilog.Formatting.Compact
{
Expand Down Expand Up @@ -63,11 +65,11 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
output.Write("{\"@t\":\"");
output.Write(logEvent.Timestamp.UtcDateTime.ToString("O"));
output.Write("\",\"@m\":");
var message = logEvent.MessageTemplate.Render(logEvent.Properties);
var message = logEvent.MessageTemplate.Render(logEvent.Properties, CultureInfo.InvariantCulture);
JsonValueFormatter.WriteQuotedJsonString(message, output);
output.Write(",\"@i\":\"");
var id = EventIdHash.Compute(logEvent.MessageTemplate.Text);
output.Write(id.ToString("x8"));
output.Write(id.ToString("x8",CultureInfo.InvariantCulture));
output.Write('"');

if (logEvent.Level != LogEventLevel.Information)
Expand All @@ -82,7 +84,21 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
output.Write(",\"@x\":");
JsonValueFormatter.WriteQuotedJsonString(logEvent.Exception.ToString(), output);
}

if (logEvent.TraceId != null)
{
output.Write(",\"@tr\":\"");
output.Write(logEvent.TraceId.Value.ToHexString());
output.Write('\"');
}

if (logEvent.SpanId != null)
{
output.Write(",\"@sp\":\"");
output.Write(logEvent.SpanId.Value.ToHexString());
output.Write('\"');
}

foreach (var property in logEvent.Properties)
{
var name = property.Key;
Expand Down
54 changes: 30 additions & 24 deletions src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>A simple, compact JSON-based event format for Serilog.</Description>
<VersionPrefix>1.1.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net452;netstandard1.1;netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Formatting.Compact</AssemblyName>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Serilog.Formatting.Compact</PackageId>
<PackageTags>serilog;json</PackageTags>
<PackageIconUrl>http://serilog.net/images/serilog-extension-nuget.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/serilog/serilog-formatting-compact</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup>
<Description>A simple, compact JSON-based event format for Serilog.</Description>
<VersionPrefix>2.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net471</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageIcon>serilog-extension-nuget.png</PackageIcon>
<PackageTags>serilog;json</PackageTags>
<PackageProjectUrl>https://github.com/serilog/serilog-formatting-compact</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/serilog/serilog-formatting-compact</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AnalysisLevel>6.0-recommended</AnalysisLevel>
<RootNamespace>Serilog</RootNamespace>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.8.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.0" />
<None Include="../../assets/serilog-extension-nuget.png" Pack="True" Visible="False" PackagePath="" />
<None Include="../../README.md" Pack="True" Visible="False" PackagePath="" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions test/Serilog.Formatting.Compact.Tests/CompactJsonFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json.Linq;
using Serilog.Events;
using Xunit;
using Serilog.Formatting.Compact.Tests.Support;
using Serilog.Parsing;


namespace Serilog.Formatting.Compact.Tests
Expand Down Expand Up @@ -77,5 +81,18 @@ public void TimestampIsUtc()
Assert.True(jobject.TryGetValue("@t", out val));
Assert.EndsWith("Z", val.ToObject<string>());
}

[Fact]
public void TraceAndSpanIdsGenerateValidJson()
{
var traceId = ActivityTraceId.CreateRandom();
var spanId = ActivitySpanId.CreateRandom();
var evt = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null,
new MessageTemplate(Enumerable.Empty<MessageTemplateToken>()), Enumerable.Empty<LogEventProperty>(),
traceId, spanId);
var json = AssertValidJson(log => log.Write(evt));
Assert.Equal(traceId.ToHexString(), json["@tr"]);
Assert.Equal(spanId.ToHexString(), json["@sp"]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FormattingBenchmarks()

StringWriter _buffer;

[Setup]
[GlobalSetup]
public void InitBuffer()
{
_buffer = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class FormattingBenchmarksConfig : ManualConfig
{
public FormattingBenchmarksConfig()
{
this.Add(Job.Default.WithTargetCount(new Count(10)));
this.AddJob(Job.Default.WithIterationCount(10));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net452;netcoreapp2.1</TargetFrameworks>
<AssemblyName>Serilog.Formatting.Compact.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<IsPackable>false</IsPackable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net48</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netcoreapp3.1;net6.0;net7.0;</TargetFrameworks>
<AssemblyName>Serilog.Formatting.Compact.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<IsPackable>false</IsPackable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.9.7-beta" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Formatting.Compact\Serilog.Formatting.Compact.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Formatting.Compact\Serilog.Formatting.Compact.csproj" />
</ItemGroup>

</Project>

0 comments on commit 91be91b

Please sign in to comment.