serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
307 stars 97 forks source link

UseSerilog implementation #163

Closed dazinator closed 4 years ago

dazinator commented 4 years ago

Hello it's me again!

I couldn't use UseSerilog() in my application for reasons delved into here (my application is complex using autofac and child containers, and my own library for multitenancy) - and my workaround was to do this instead:

               webhostBuilder.ConfigureLogging((logging) =>
                {
                    logging.ClearProviders();// clears microsoft providers registered by default like console.
                    logging.AddSerilog(Logger);
                });

Which works. I raise this here because I thought maybe you could simplify the UseSerilog() implementation to call this method on the host builder instead, and then you could ditch your custom ILoggerFactory ?

nblumhardt commented 4 years ago

Thanks for the note! The workaround you're using is the supported one, here; we deliberately use our own ILoggerFactory to avoid inconsistencies/edge cases around filtering and configuration, but the Serilog provider works when the default approach isn't viable 👍