Skip to content

Commit 91be91b

Browse files
authored
Merge pull request #57 from serilog/dev
2.0.0 Release
2 parents b81d6f3 + 8082e56 commit 91be91b

13 files changed

+143
-80
lines changed

Build.ps1

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
Write-Output "build: Build started"
2+
13
Push-Location $PSScriptRoot
24

3-
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
5+
if(Test-Path .\artifacts) {
6+
Write-Output "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
8+
}
49

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

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

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

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

17-
Pop-Location
23+
if($suffix) {
24+
& dotnet pack src\Serilog.Formatting.Compact --configuration Release --no-build --no-restore -o artifacts --version-suffix=$suffix
25+
} else {
26+
& dotnet pack src\Serilog.Formatting.Compact --configuration Release --no-build --no-restore -o artifacts
1827
}
1928

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

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

26-
Pop-Location
27-
}
33+
& dotnet test test\Serilog.Formatting.Compact.Tests --configuration Release --no-build --no-restore
2834

29-
Pop-Location
35+
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
supported targets: netstandard2.0, net6.0
2+
updated packages in test proj

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ See `test/Serilog.Formatting.Compact.Tests/FormattingBenchmarks.cs`.
140140
|:------------------------------ |----------: |---------: |------: |
141141
| `JsonFormatter` | 11.2775 µs | 0.0682 µs | 1.00 |
142142
| `CompactJsonFormatter` | 6.0315 µs | 0.0429 µs | 0.53 |
143-
| `RenderedJsonFormatter` | 13.7585 µs | 0.1194 µs | 1.22 |
143+
| `JsonFormatter(renderMessage: true)` | 13.7585 µs | 0.1194 µs | 1.22 |
144144
| `RenderedCompactJsonFormatter` | 7.0680 µs | 0.0605 µs | 0.63 |
145145

146146
### Tools
147147

148148
Several tools are available for working with the CLEF format.
149149

150+
* **[_Analogy.LogViewer.Serilog_](https://github.com/Analogy-LogViewer/Analogy.LogViewer.Serilog)** - CLEF parser for [Analogy Log Viewer](https://github.com/Analogy-LogViewer/Analogy.LogViewer)
150151
* **[`clef-tool`](https://github.com/datalust/clef-tool)** - a CLI application for processing CLEF files
151-
* **[Compact Log Format Viewer](https://github.com/warrenbuckley/Compact-Log-Format-Viewer)** - a cross-platform viewer for CLEF JSON files
152-
* **[_Serilog.Formatting.Compact.Reader_](https://github.com/serilog/serilog-formatting-compact-reader)** - convert CLEF JSON documents back into Serilog `LogEvent`s
153-
152+
* **[Compact Log Format Viewer](https://github.com/warrenbuckley/Compact-Log-Format-Viewer)** - a cross-platform viewer for CLEF files
153+
* **[`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
154+
* **[_Serilog.Formatting.Compact.Reader_](https://github.com/serilog/serilog-formatting-compact-reader)** - convert CLEF documents back into Serilog `LogEvent`s

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2019
3+
image: Visual Studio 2022
44
configuration: Release
55
install:
66
- ps: ./Setup.ps1
77
build_script:
88
- ps: ./Build.ps1
9-
test: off
9+
test: false
1010
artifacts:
1111
- path: artifacts/Serilog.*.nupkg
1212
deploy:
1313
- provider: NuGet
1414
api_key:
15-
secure: ptRAVPZZO/hlZUv5e/yLnHF7aAh8tQmBfvLt64Qrvhoe7I/mbbPNI6RYm92g5EzG
15+
secure: 4nUKbHgmKmedr6dDtCT2uWVLeQl+tFqO+y9LvRi3nk7cvD/DnOYI1ZqajsgDqxnH
1616
skip_symbols: true
1717
on:
1818
branch: /^(master|dev)$/

assets/serilog-extension-nuget.png

21.9 KB
Loading

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "3.0.100"
3+
"version": "7.0.304"
44
}
55
}

src/Serilog.Formatting.Compact/Formatting/Compact/CompactJsonFormatter.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
// limitations under the License.
1414

1515
using System;
16+
using System.Globalization;
1617
using System.IO;
1718
using System.Linq;
1819
using Serilog.Events;
1920
using Serilog.Formatting.Json;
2021
using Serilog.Parsing;
22+
// ReSharper disable MemberCanBePrivate.Global
2123

2224
namespace Serilog.Formatting.Compact
2325
{
@@ -76,12 +78,12 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
7678
{
7779
output.Write(",\"@r\":[");
7880
var delim = "";
79-
foreach (var r in tokensWithFormat)
81+
foreach (PropertyToken r in tokensWithFormat)
8082
{
8183
output.Write(delim);
8284
delim = ",";
8385
var space = new StringWriter();
84-
r.Render(logEvent.Properties, space);
86+
r.Render(logEvent.Properties, space, CultureInfo.InvariantCulture);
8587
JsonValueFormatter.WriteQuotedJsonString(space.ToString(), output);
8688
}
8789
output.Write(']');
@@ -100,6 +102,20 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
100102
JsonValueFormatter.WriteQuotedJsonString(logEvent.Exception.ToString(), output);
101103
}
102104

105+
if (logEvent.TraceId != null)
106+
{
107+
output.Write(",\"@tr\":\"");
108+
output.Write(logEvent.TraceId.Value.ToHexString());
109+
output.Write('\"');
110+
}
111+
112+
if (logEvent.SpanId != null)
113+
{
114+
output.Write(",\"@sp\":\"");
115+
output.Write(logEvent.SpanId.Value.ToHexString());
116+
output.Write('\"');
117+
}
118+
103119
foreach (var property in logEvent.Properties)
104120
{
105121
var name = property.Key;

src/Serilog.Formatting.Compact/Formatting/Compact/RenderedCompactJsonFormatter.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
// limitations under the License.
1414

1515
using System;
16+
using System.Globalization;
1617
using System.IO;
1718
using Serilog.Events;
1819
using Serilog.Formatting.Json;
20+
// ReSharper disable MemberCanBePrivate.Global
1921

2022
namespace Serilog.Formatting.Compact
2123
{
@@ -63,11 +65,11 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
6365
output.Write("{\"@t\":\"");
6466
output.Write(logEvent.Timestamp.UtcDateTime.ToString("O"));
6567
output.Write("\",\"@m\":");
66-
var message = logEvent.MessageTemplate.Render(logEvent.Properties);
68+
var message = logEvent.MessageTemplate.Render(logEvent.Properties, CultureInfo.InvariantCulture);
6769
JsonValueFormatter.WriteQuotedJsonString(message, output);
6870
output.Write(",\"@i\":\"");
6971
var id = EventIdHash.Compute(logEvent.MessageTemplate.Text);
70-
output.Write(id.ToString("x8"));
72+
output.Write(id.ToString("x8",CultureInfo.InvariantCulture));
7173
output.Write('"');
7274

7375
if (logEvent.Level != LogEventLevel.Information)
@@ -82,7 +84,21 @@ public static void FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFo
8284
output.Write(",\"@x\":");
8385
JsonValueFormatter.WriteQuotedJsonString(logEvent.Exception.ToString(), output);
8486
}
87+
88+
if (logEvent.TraceId != null)
89+
{
90+
output.Write(",\"@tr\":\"");
91+
output.Write(logEvent.TraceId.Value.ToHexString());
92+
output.Write('\"');
93+
}
8594

95+
if (logEvent.SpanId != null)
96+
{
97+
output.Write(",\"@sp\":\"");
98+
output.Write(logEvent.SpanId.Value.ToHexString());
99+
output.Write('\"');
100+
}
101+
86102
foreach (var property in logEvent.Properties)
87103
{
88104
var name = property.Key;
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<Description>A simple, compact JSON-based event format for Serilog.</Description>
5-
<VersionPrefix>1.1.0</VersionPrefix>
6-
<Authors>Serilog Contributors</Authors>
7-
<TargetFrameworks>net452;netstandard1.1;netstandard2.0</TargetFrameworks>
8-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
9-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
10-
<AssemblyName>Serilog.Formatting.Compact</AssemblyName>
11-
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
12-
<SignAssembly>true</SignAssembly>
13-
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
14-
<PackageId>Serilog.Formatting.Compact</PackageId>
15-
<PackageTags>serilog;json</PackageTags>
16-
<PackageIconUrl>http://serilog.net/images/serilog-extension-nuget.png</PackageIconUrl>
17-
<PackageProjectUrl>https://github.com/serilog/serilog-formatting-compact</PackageProjectUrl>
18-
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
19-
</PropertyGroup>
3+
<PropertyGroup>
4+
<Description>A simple, compact JSON-based event format for Serilog.</Description>
5+
<VersionPrefix>2.0.0</VersionPrefix>
6+
<Authors>Serilog Contributors</Authors>
7+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net471</TargetFrameworks>
8+
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
10+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
12+
<SignAssembly>true</SignAssembly>
13+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
14+
<PackageIcon>serilog-extension-nuget.png</PackageIcon>
15+
<PackageTags>serilog;json</PackageTags>
16+
<PackageProjectUrl>https://github.com/serilog/serilog-formatting-compact</PackageProjectUrl>
17+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
18+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
19+
<RepositoryUrl>https://github.com/serilog/serilog-formatting-compact</RepositoryUrl>
20+
<RepositoryType>git</RepositoryType>
21+
<AnalysisLevel>6.0-recommended</AnalysisLevel>
22+
<RootNamespace>Serilog</RootNamespace>
23+
<PackageReadmeFile>README.md</PackageReadmeFile>
24+
</PropertyGroup>
2025

21-
<ItemGroup>
22-
<PackageReference Include="Serilog" Version="2.8.0" />
23-
</ItemGroup>
26+
<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
27+
<WarningLevel>5</WarningLevel>
28+
</PropertyGroup>
2429

25-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
26-
<Reference Include="System" />
27-
<Reference Include="Microsoft.CSharp" />
28-
</ItemGroup>
30+
<ItemGroup>
31+
<PackageReference Include="Serilog" Version="3.1.0" />
32+
<None Include="../../assets/serilog-extension-nuget.png" Pack="True" Visible="False" PackagePath="" />
33+
<None Include="../../README.md" Pack="True" Visible="False" PackagePath="" />
34+
</ItemGroup>
2935

3036
</Project>

test/Serilog.Formatting.Compact.Tests/CompactJsonFormatterTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.Linq;
24
using Newtonsoft.Json.Linq;
5+
using Serilog.Events;
36
using Xunit;
47
using Serilog.Formatting.Compact.Tests.Support;
8+
using Serilog.Parsing;
59

610

711
namespace Serilog.Formatting.Compact.Tests
@@ -77,5 +81,18 @@ public void TimestampIsUtc()
7781
Assert.True(jobject.TryGetValue("@t", out val));
7882
Assert.EndsWith("Z", val.ToObject<string>());
7983
}
84+
85+
[Fact]
86+
public void TraceAndSpanIdsGenerateValidJson()
87+
{
88+
var traceId = ActivityTraceId.CreateRandom();
89+
var spanId = ActivitySpanId.CreateRandom();
90+
var evt = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null,
91+
new MessageTemplate(Enumerable.Empty<MessageTemplateToken>()), Enumerable.Empty<LogEventProperty>(),
92+
traceId, spanId);
93+
var json = AssertValidJson(log => log.Write(evt));
94+
Assert.Equal(traceId.ToHexString(), json["@tr"]);
95+
Assert.Equal(spanId.ToHexString(), json["@sp"]);
96+
}
8097
}
8198
}

0 commit comments

Comments
 (0)