serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
309 stars 99 forks source link

Identify gaps in the `UseSerilog()` ASP.NET Core integration experience #103

Closed nblumhardt closed 6 years ago

nblumhardt commented 6 years ago

From #98. List to be constructed:

Mystere commented 6 years ago

The documentation suggests that for aspnet core 2.0 to configuring Serilog in the CreateServices section, however, the newer way to do this is in the BuildWebHost configuration.

For example:

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureLogging(logging =>
                    {
                        logging.AddSerilog();
                    })
                    .UseStartup<Startup>()
                .Build();

Perhaps the documentation should be updated.

Actually, the documentation is contradictory, in one place it says to use .UseSerilog() and in another it says to use .AddSerilog().

ie:

ASP.NET Core 2.0+ Instructions ASP.NET Core 2.0 applications should prefer Serilog.AspNetCore and UseSerilog() instead.

and

Finally, for .NET Core 2.0+, in your Startup class's Configure() method, remove the existing logger configuration entries and call AddSerilog() on the provided loggingBuilder.

I should note that despite it saying ".NET Core" vs "ASP.NET Core", it's still referring to the IHostingEnvironment and log entry examples indicate it's asp.net.

nblumhardt commented 6 years ago

The code and docs at https://github.com/serilog/serilog-aspnetcore have had a few updates since this ticket was raised; closing.

phougatv commented 4 years ago

Install Serilog.AspNetCore package and include it in your program file, to use UseSerilog().