Apart from installing Serilog.AspNetCore
you could also install Serilog.Extensions.Logging
and use these lines of code. This will give you some ideas how UseSerilog()
works under the hood (well, more or less this way :D).
var serilogLogger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Verbose()
.WriteTo.Debug() // Serilog.Sinks.Debug
.CreateLogger();
var microsoftLogger = new SerilogLoggerFactory(serilogLogger)
.CreateLogger<IMyService>(); // creates an instance of ILogger<IMyService>
Or if you need to use the logger in the DI container use these lines of code:
Log.Logger = serilogLogger;
var container = new ServiceCollection()
.AddLogging(x => x.AddSerilog())
.BuildServiceProvider(true);