My Serilog configuration code looks like this:
Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.Enrich.FromLogContext()
.Mi
I think to make it elegant and still do it in code, you do have to extend the API and create your own extension methods that encapsulate the condition checks and update the builder with the correct sink and parameters.
Something like
Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.Enrich.FromLogContext()
.MinimumLevel.Warning()
.WriteToConsoleIfEnabled() // <---
.WriteToFileIfEnabled() // <---
.CreateLogger();
On a different note, have you considered using Serilog.Settings.AppSettings or Serilog.Settings.Configuration instead? The configuration in code gets much cleaner, and you can add/remove sinks in the configuration file as you wish...
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger()