I Net Core 5 I used to configure Serilog using the recommended approach:
public static void Main(string[] args) {
Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
try {
Log.Information("Starting up");
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex) {
Log.Fatal(ex, "Application start-up failed");
}
finally {
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
How to configure Serilog in Net 6 using WebApplicationBuilder
:
var builder = WebApplication.CreateBuilder(args);
// Configure Serilog
var app = builder.Build();