title: Serilog, Microsoft.Extensions.Logging and Autofac
body: <p>I have an Asp Net Core API that targets the .Net Framework 4.6.1.
  In this project I use Serilog with Microsoft.Extensions.Logging and also Auofac for DI.
  Using ILogger&lt; T> logger with DI in the controller constructor works perfectlly and I also get logs.</p>
  
  <p>The fun starts when in the API I need to use another project the use Microsoft.Extensions.Logging and Autofac and expects to receive ILogger&lt; T> in some constructors.
  I've installed the same version of Microsoft.Extensions.Logging in both projects.</p>
  
  <p>I get the fallowing exception:</p>
  
  <blockquote>
    <p>Autofac.Core.DependencyResolutionException: 'An exception was thrown while activating Microsoft.Extensions.Logging.Logger<code>1[[Microsoft.AspNetCore.Hosting.Internal.WebHost, Microsoft.AspNetCore.Hosting, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] -&gt; Microsoft.Extensions.Logging.LoggerFactory -&gt; λ:Microsoft.Extensions.Logging.ILoggerProvider[] -&gt; Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider -&gt; Microsoft.Extensions.Options.OptionsMonitor</code>1[[Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions, Microsoft.Extensions.Logging.Console, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] -> Microsoft.Extensions.Options.OptionsFactory<code>1[[Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions, Microsoft.Extensions.Logging.Console, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] -&gt; λ:Microsoft.Extensions.Options.IConfigureOptions</code>1[[Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions, Microsoft.Extensions.Logging.Console, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]][] -> Microsoft.Extensions.Logging.Console.ConsoleLoggerOptionsSetup -> Microsoft.Extensions.Logging.Configuration.LoggerProviderConfiguration`1[[Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider, Microsoft.Extensions.Logging.Console, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].'</p>
    
    <p>Inner Exception1:
    DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.Extensions.Logging.Configuration.ILoggerProviderConfigurationFactory)' on type 'LoggerProviderConfiguration`1'.</p>
    
    <p>Inner Exception2:
    MethodAccessException: Attempt by method 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(System.Type)' to access method 'Microsoft.Extensions.Logging.ProviderAliasUtilities.GetAlias(System.Type)' failed.</p>
  </blockquote>
  
  <p>These are the packages for the API:</p>
  
  <pre><code>&lt;PackageReference Include="Autofac" Version="4.9.4" /&gt;
      &lt;PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.1" /&gt;
      &lt;PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" /&gt;
      &lt;PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" /&gt;
      &lt;PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /&gt;
  </code></pre>
  
  <p>And these are the packages from the other project:</p>
  
  <pre><code> &lt;PackageReference Include="Autofac" Version="4.9.4" /&gt;
      &lt;PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.1" /&gt;
  </code></pre>