title: NLog works in ASP.NET Core App but not in .NET Core xUnit Test Project
body: <p>I've created a .NET Core class library that defines utility class interfaces and that implements each interface for things like database access via ADO.NET, etc.</p>
  
  <p>Each implementation class utilizes NLog.  This works great in an ASP.NET Core Web application that includes and references the .NET Core class library.</p>
  
  <p>However, when I try to instantiate these same implementation classes in the context of a .NET Core xUnit Test project, I get</p>
  
  <blockquote>
    <p>Unable to cast object of type 'NLog.Logger' to type 'Microsoft.Extensions.Logging.ILogger'</p>
  </blockquote>
  
  <p>I've searched for similar issues but found none.</p>
  
  <p>In each class I've declared a private readonly variable:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private readonly ILogger&lt;DatabasePersistenceAdoDotNet&gt; _logger = null;
  </code></pre>
  
  <p>And I'm instantiating this variable like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>_logger = (ILogger&lt;DatabasePersistenceAdoDotNet&gt;)NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
  </code></pre>
  
  <p>This works in an ASP.NET Core Web application that includes and references the .NET Core class library but blows up in my .NET Core xUnit Test project.</p>
  
  <p>I suspect that this has something to do with ASP.NET's dependency inject not being available in the .NET Core xUnit Test project, but I can't figure out how to make my utility package work correctly in both contexts.</p>