logging - SerilogTracing generates duplicate trace id for independent requests .NET 7 - Stack Overflow

admin2025-04-18  4

I added SEQ Tracing by using SerilogTracing in an ASP.NET Core 7 Web API using following code in program.cs:

var logger= new LoggerConfiguration() 
 .ReadFrom.Configuration(configuration); 

using var _ = new ActivityListenerConfiguration()
.Instrument.AspNetCoreRequests()
.Instrument.SqlClientCommands()
.TraceToSharedLogger();

and then use Serilog by calling IHostBuilder.UseSerilog().

Reference: SEQ Tracing from .NET using SerilogTracing

I've observed that some independent records share a common trace ID, even though the logs are ingested from different physical servers.

Is the current minimal configuration for tracing sufficient, or do I need to handle the trace ID manually? According to the documentation, the Activity listener configuration is added in program.cs. Is this the appropriate location for adding the Activity listener configurations?

转载请注明原文地址:http://anycun.com/QandA/1744937655a89742.html