Can a Serilog.ILogger be converted to a Microsoft.Extensions.Logging.ILogger?

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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)