title: Unable to resolve ILogger from Microsoft.Extensions.Logging
body: <p>I've configured my console application's <code>Main</code> like so</p>
  <pre class="lang-cs prettyprint-override"><code>var services = new ServiceCollection()
      .AddLogging(logging =&gt; logging.AddConsole())
      .BuildServiceProvider();
  </code></pre>
  <p>And then I try to use it in another class like so</p>
  <pre class="lang-cs prettyprint-override"><code>private readonly ILogger _logger;
      
  public MyClass(ILogger logger)
  {
      _logger = logger;
  }
  
  public void MyFunc()
  {
      _logger.Log(LogLevel.Error, &quot;My Message&quot;);
  }
  </code></pre>
  <blockquote>
  <p>System.InvalidOperationException: 'Unable to resolve service for type
  'Microsoft.Extensions.Logging.ILogger'</p>
  </blockquote>
  <p>I've tried the solutions <a href="https://stackoverflow.com/a/51329388/2025666">here</a> but it didn't work for me.</p>
  <p><strong>Edit</strong>
  Based on Yaakov's comment below and <a href="https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/92#issuecomment-223991293" rel="noreferrer">this Github comment</a> I'm able to resolve it correctly by doing this</p>
  <pre class="lang-cs prettyprint-override"><code>public MyClass(ILogger&lt;MyClass&gt; logger)
  {
      _logger = logger;
  }
  </code></pre>
  <p>I would have preferred to have this in the initial <code>BuildServiceProvider</code> but looks like I'm gonna have to repeat this every time I want to use the logger (or create my own ILogger).</p>