Skip to content

Commit

Permalink
Force W3C activity ids on .NET 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Oct 3, 2023
1 parent 5458567 commit 6585051
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="All" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<TargetFrameworks>net7.0;net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework) == 'net472' ">
<DefineConstants>$(DefineConstants);FORCE_W3C_ACTIVITY_ID</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj" />
Expand All @@ -12,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion test/Serilog.Extensions.Logging.Tests/SerilogLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void LogsCorrectMessage()

Assert.Equal(3, sink.Writes.Count);

Assert.Equal(1, sink.Writes[0].Properties.Count);
Assert.Single(sink.Writes[0].Properties);
Assert.Empty(sink.Writes[0].RenderMessage());

Assert.Equal(2, sink.Writes[1].Properties.Count);
Expand Down Expand Up @@ -501,6 +501,11 @@ public void Emit(LogEvent logEvent)
[Fact]
public void TraceAndSpanIdsAreCaptured()
{
#if FORCE_W3C_ACTIVITY_ID
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
#endif

using var listener = new ActivityListener();
listener.ShouldListenTo = _ => true;
listener.Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData;
Expand Down

0 comments on commit 6585051

Please sign in to comment.