I have a .Net Core 5 app with Serilog. I am testing error logging and I have a class that cannot be instantiated because I commented out some services in the DI registration. This is my Program.cs file:
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.File("Logs/Startup.txt", Serilog.Events.LogEventLevel.Verbose)
.CreateLogger();
try
{
Log.Information("Starting up");
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application start-up failed");
Environment.Exit(1);
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
In the Startup.txt
file I am only seeing the Information
and not the errors. Ideas?