Use Serilog with Microsoft.Extensions.Logging.ILogger

In the Serilog.Extensions.Logging assembly there is a extension method on IloggingBuilder called AddSerilog (it’s in the Serilog namespace) that will allow you to use Serilog for logging. For example:

.NET Core 2.2 and earlier (using WebHost):

WebHost.CreateDefaultBuilder(args)
    .ConfigureLogging(logging =>
    {
        logging.ClearProviders();
        logging.AddSerilog();
    });

.NET Core 3.1 and later (using generic Host for either web or console apps):

Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()})
    .UseSerilog();

Now the ILogger and ILogger<> implementation will call into Serilog.

Leave a Comment

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