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