File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed
test/Serilog.AspNetCore.Tests Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 11using Serilog ;
2+ using Serilog . Templates ;
23
34namespace Sample ;
45
@@ -39,6 +40,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
3940 . ReadFrom . Configuration ( context . Configuration )
4041 . ReadFrom . Services ( services )
4142 . Enrich . FromLogContext ( )
42- . WriteTo . Console ( ) )
43+ . WriteTo . Console ( new ExpressionTemplate (
44+ // Include trace and span ids when present.
45+ "[{@t:HH:mm:ss} {@l:u3}{#if @tr is not null} ({@tr}:{@sp}){#end}] {@m}\n {@x}" ) ) )
4346 . ConfigureWebHostDefaults ( webBuilder => webBuilder . UseStartup < Startup > ( ) ) ;
44- }
47+ }
Original file line number Diff line number Diff line change 77 <ItemGroup >
88 <ProjectReference Include =" ..\..\src\Serilog.AspNetCore\Serilog.AspNetCore.csproj" />
99 </ItemGroup >
10+
11+ <ItemGroup >
12+ <PackageReference Include =" Serilog.Expressions" Version =" 4.0.0-*" />
13+ </ItemGroup >
1014
1115</Project >
Original file line number Diff line number Diff line change 2727 <PackageReference Include =" Serilog.Sinks.Console" Version =" 4.0.1" />
2828 <PackageReference Include =" Serilog.Sinks.File" Version =" 5.0.0" />
2929 <PackageReference Include =" Serilog.Sinks.Debug" Version =" 2.0.0" />
30- <PackageReference Include =" Serilog.Formatting.Compact" Version =" 1.1.0 " />
30+ <PackageReference Include =" Serilog.Formatting.Compact" Version =" 2.0.0-* " />
3131 </ItemGroup >
3232
3333 <ItemGroup >
3636 <PackageReference Include =" Serilog.Settings.Configuration" Version =" 7.0.0" />
3737 <PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 7.0.0" />
3838 <PackageReference Include =" Microsoft.Extensions.Logging" Version =" 7.0.0" />
39+ <!-- Temporary addition to pull in trace/span support -->
40+ <PackageReference Include =" Serilog.Extensions.Logging" Version =" 7.0.1-*" />
3941 </ItemGroup >
4042
4143 <ItemGroup Condition =" '$(TargetFramework)' != 'net462' and '$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netstandard2.1' " >
Original file line number Diff line number Diff line change @@ -164,6 +164,19 @@ WebApplicationFactory<TestStartup> Setup(
164164
165165 return web ;
166166 }
167+
168+ [ Fact ]
169+ public async Task RequestLoggingMiddlewareShouldAddTraceAndSpanIds ( )
170+ {
171+ var ( sink , web ) = Setup ( ) ;
172+
173+ await web . CreateClient ( ) . GetAsync ( "/resource" ) ;
174+
175+ var completionEvent = sink . Writes . First ( logEvent => Matching . FromSource < RequestLoggingMiddleware > ( ) ( logEvent ) ) ;
176+
177+ Assert . NotNull ( completionEvent . TraceId ) ;
178+ Assert . NotNull ( completionEvent . SpanId ) ;
179+ }
167180
168181 ( SerilogSink , WebApplicationFactory < TestStartup > ) Setup (
169182 Action < RequestLoggingOptions > ? configureOptions = null ,
You can’t perform that action at this time.
0 commit comments