Seems that you are missing .UseSerilog
inside Program
. Here is my template for Program
:
public class Program
{
public static void Main(string[] args)
{
var webHost = CreateHostBuilder(args)
.Build();
// access any service from here by using webHost.Services.GetService<...
Log.Information("Starting MyWebApp");
// ... configure Serilog
try
{
webHost.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "The application failed to start correctly.");
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog();
}