Closed nblumhardt closed 6 months ago
Should this be builder.Services.AddSerilog()
or builder.Logging.Services.AddSerilog()
?
Digging into this some more, I think it should actually be:
builder.Host.UseSerilog()
The reason being, currently, that the callback accepted by this version exposes the appsettings.json IConfiguration
, while builder.Services.AddSerilog()
doesn't.
I think builder.Services
and builder.Logging.Services
will end up equivalent, but let me know if it turns out that I'm mistaken :-)
Just noting that the minimal API template uses WebApplication.CreateBuilder()
, which is different from the IHostApplicationBuilder
being discussed in https://github.com/serilog/serilog-extensions-hosting/issues/76
Seems like we should encourage builder.Services.AddSerilog(lc => ..)
everywhere, since it works with both host styles, and handles configuration a bit more elegantly with AddSerilog(lc => lc.ReadFrom.Configuration(builder.Configuration))
instead of needing the second callback arg.
See https://github.com/serilog/serilog/issues/1855#issuecomment-2024546740