How do I interpret Serilog configuration in ASP.NET Core 2.1?
Looking on how to install, configure and use Serilog on .NET Core 2.1 API project, I found this article very useful.
About configuration file, on the Serilog GitHub repository there's a specific page about Serilog.Settings.Configuration package.
Although you've added configuration to appsettings.json
for overriding the Serilog logging levels, you've not actually passed said configuration into Serilog. At the simplest level, this requires you to install the Serilog.Settings.Configuration nuget package. Once you've done that, you can add a call to ReadFrom.Configuration
, like so:
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration.GetSection("Logging"))
.Enrich.FromLogContext()
// ...
This is all you need in order to get your configuration into Serilog, but you do have other issues with how you're still using ILoggerFactory
inside of Configure
(this changed in ASP.NET Core 2.0). One of the issues this is likely causing for you is that both ASP.NET Core's Console provider and the Serilog Console sink are writing logs. If you need help with any of that, it's well documented online, but of course you can create additional Stack Overflow questions if absolutely necessary.
Nicholas Blumhardt blogged about the ASP.NET Core 2.0 logging changes - This is a useful read that should help simplify your Serilog + ASP.NET Core experience greatly.