serilog / serilog-extensions-hosting

Serilog logging for Microsoft.Extensions.Hosting
Apache License 2.0
141 stars 34 forks source link

Serilog breaks .NET Aspire structured logging #91

Open krzysiek-b opened 5 months ago

krzysiek-b commented 5 months ago

Description Looks like currently when using

builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration.ReadFrom.Configuration(context.Configuration));

in ASP.NET app using .NET 8 Serilog breaks .NET Aspire logging integration. The structured logs tab is empty.

Expected behavior Structured logs tab should have all logs.

bartelink commented 5 months ago

Someone somewhere is going to have to analyze more deeply to repro. A bug is a set of steps and/or failing test that replicates a validated problem that needs a code change to fix...

You'll find the serilog tag on stack overflow is a better way to to/fro on troubleshooting/narrowing down issues like this, as there's no herd of highly paid Serilog maintainers at a loose end, swarming around looking for things to attempt to repro any reported problems...

nblumhardt commented 5 months ago

builder.Host.UseSerilog() registers Serilog as the logger factory (complete logging pipeline). But, Aspire configures its default logging settings via Microsoft.Extensions.Logging's (the other logging pipeline implementation, which UseSerilog() replaces).

The two options are:

  1. Add Serilog as a logger provider, with builder.Logging.AddSerilog(); builder.Logging is MEL's configuration entry point, wiring things up this way will slot Serilog in under MEL, routing MEL events to it. The downside is that you'll have two logging pipelines running, and if you write to Serilog's APIs directly, the events won't reach other MEL providers.
  2. Install Serilog.Sinks.OpenTelemetry and configure WriteTo.OpenTelemetry() to point to the Aspire dashboard. You'll need to dig around a bit to find the right endpoint URL/protocol, but should be doable.

Keen to hear how you go; hope this helps!