title: ILoggerFactory in extension method - lifetime and dispose
body: <p>To create a <code>ILogger</code> in extension methods I store a <code>ILoggerFactory</code> in a static class</p>
  
  <pre><code>public static class ApplicationLogging
  {
      public static ILoggerFactory LoggerFactory { get; set; }
  
      public static ILogger CreateLogger&lt;T&gt;() =&gt;
          LoggerFactory?.CreateLogger&lt;T&gt;();
  
      public static ILogger CreateLogger(string name) =&gt;
          LoggerFactory?.CreateLogger(name);
  
  }
  </code></pre>
  
  <p>which is set with</p>
  
  <pre><code>public void Configure(ILoggerFactory loggerFactory)
  {
     ...
      ApplicationLogging.LoggerFactory = loggerFactory;
  }
  </code></pre>
  
  <p>However, I notice that <code>ILoggerFactory</code> gets disposed</p>
  
  <blockquote>
    <p>System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'LoggerFactory'.
        at Microsoft.Extensions.Logging.LoggerFactory.CreateLogger(String categoryName)
        at Microsoft.Extensions.Logging.Logger`1..ctor(ILoggerFactory factory)
        at Microsoft.Extensions.Logging.LoggerFactoryExtensions.CreateLogger[T](ILoggerFactory factory)</p>
  </blockquote>
  
  <p>So is it not correct to store a <code>ILoggerFactory</code>? What would be the alternative to access it from extension methods? Store <code>IServiceProvider</code> and <code>GetRequiredService&lt;ILoggerFactory&gt;</code> ?</p>