My Serilog configuration code looks like this:
Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.Enrich.FromLogContext()
.Mi
Serilog 2.9.0 introduces conditional sinks. Using .WriteTo.Conditional
you specify the condition that defines if the sink will be written to or not.
e.g.
bool enableConsoleLogging = ...
bool enableFileLogging = ...
var builder = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.Enrich.FromLogContext()
.MinimumLevel.Warning()
.WriteTo.Conditional(evt => enableConsoleLogging, wt => wt.Console())
.WriteTo.Conditional(evt => enableFileLogging, wt => wt.File(...));
Log.Logger = builder.CreateLogger();
// ...