Skip to content

2.0.0 Release #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bcb0cea
Dev version bump [skip ci]
nblumhardt Oct 17, 2019
06ef9d8
Use less confusing name for rendered `JsonFormatter` in the benchmark…
nblumhardt Feb 13, 2020
468c643
Update README.md
LiorBanai Mar 6, 2020
ad35ff5
Simplify description of Analogy CLEF parser
nblumhardt Mar 6, 2020
8b7035f
Merge pull request #32 from LiorBanai/dev
nblumhardt Mar 6, 2020
1eca9e5
README formatting tidy-up; alphabetically sort tools; add `seqcli`
nblumhardt Mar 6, 2020
7140c01
Update Serilog dependency version
bdovaz May 7, 2021
c3fe3c6
Merge pull request #43 from bdovaz/dev
nblumhardt May 11, 2021
8393e0a
Update publishing key
nblumhardt May 11, 2021
2141692
build on VS 2022
SimonCropp Feb 3, 2023
b7b9ef9
supported targets: netstandard2.0, net6.0
Jul 6, 2023
ae9b27a
add argument CultureInfo.InvariantCulture to force consistent formatt…
Jul 6, 2023
b0adbda
PackageIconUrl is deprecated, added serilog-extension-nuget.png to lo…
Jul 6, 2023
6eb8935
updated formatting benchmark
Jul 6, 2023
973c40f
restored global.json, SDK 7.0.300
Jul 6, 2023
5ad414d
SDK version 7.0.8
Jul 6, 2023
f93b3df
AppVeyor SDK 7.0.304
Jul 6, 2023
4f35478
replaced Build.ps1 with adapted Build.ps1 from serilog project
Jul 6, 2023
b7b063d
test proj, removed obsolete Condition for TargetFramework net452
Jul 6, 2023
1df7654
add TargetFrameworks
Jul 10, 2023
03442a3
removed duplicate PackageIcon
Jul 10, 2023
271192c
removed AssemblyName, PackageId and Title from csproj - all are corre…
Jul 10, 2023
e338b0c
add target frameworks in test proj
Jul 10, 2023
011908d
from build.ps1 removed commented out code
Jul 10, 2023
c6f1da8
just sorted target fw's in csproj
Jul 10, 2023
f8d768f
csproj, package icon is right above commented out (and obsolete) pack…
Jul 10, 2023
6174c3c
csproj, package icon is right above commented out (and obsolete) pack…
Jul 10, 2023
cd3543f
test csproj, add missing PackageReference to "Newtonsoft.Json"
Jul 10, 2023
1d7e11b
Use less confusing name for rendered `JsonFormatter` in the benchmark…
Jul 11, 2023
29f02b3
merged 468c6435, add link to analoogy log viewer in README.md
Jul 11, 2023
0f63aeb
merged ad35ff5f, Simplify description of Analogy CLEF parser
Jul 11, 2023
eaf995e
merged 1eca9e52, README formatting tidy-up; alphabetically sort tools…
Jul 11, 2023
8d584ca
merged 8393e0ab, Update publishing key
Jul 11, 2023
2e30b05
Merge branch 'dev' into devNet6
nblumhardt Jul 19, 2023
2db445d
Merge pull request #54 from pmetz-steelcase/devNet6
nblumhardt Jul 19, 2023
8d01ad2
Include trace and span ids in output
nblumhardt Oct 3, 2023
abe544a
Merge pull request #56 from serilog/sp-tr
nblumhardt Oct 3, 2023
4fdb9e8
Update publishing key
nblumhardt Oct 4, 2023
8082e56
Update to Serilog 3.1 RTM
nblumhardt Nov 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>