There are two ways to register Serilog.
The "old" way (shown in countless SO questions and tutorials):
//builder.Logging.ClearProviders(); // optional
builder.Logging.AddSerilog();
And the "new" way (shown in the current documentation):
builder.Services.AddSerilog();
Both are supported. How do they differ?
I found the answer in a related repo issue and blog post:
builder.Logging.AddSerilog
adds Serilog as an additional provider to the logging pipelinebuilder.Services.AddSerilog
sets Serilog as the sole provider (thus the ClearProviders
call is unnecessary)builder.Host.UseSerilog
forwards to builder.Services.AddSerilog
; obsoleteTypically one would want to use builder.Services.AddSerilog
.