I have an ASP.net Core 3.1 web application. In the Program.cs class, I have implemented the CreateHostBuilder() static method similar to this:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host
.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
try
{
// do some configuration work that might fail
}
catch (Exception ex)
{
// how can I write to a log from here?
}
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
If an exception is thrown when configuring the app, how can I log it using an ILogger when I catch it?