title: Pass ILogger or ILoggerFactory to constructors in AspNet Core?
body: <p>The MS docs article <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging?tabs=aspnetcore2x#log-category" rel="noreferrer">"Introduction to Logging in ASP.NET Core"</a> gives 2 examples of constructor injection </p>
  
  <ul>
  <li><p>using <strong>ILogger</strong></p>
  
  <pre><code>private readonly ILogger _logger;   
  public TodoController(ILogger&lt;TodoController&gt; logger)  
  { 
      _logger = logger;   
  }
  </code></pre></li>
  <li><p>and <strong>ILoggerFactory</strong> </p>
  
  <pre><code>private readonly ILogger _logger;  
  public TodoController( ILoggerFactory loggerFactory)  
  {  
      _logger = loggerFactory.CreateLogger&lt;TodoController&gt;();  
  }
  </code></pre></li>
  </ul>
  
  <p>My question is what should I pass to <strong>child</strong> classes called from my controller</p>
  
  <ul>
  <li><p>pass <strong>ILoggerFactory</strong> to my child classes called from the controller and
  in each class call
  <code>LoggerFactoryExtensions.CreateLogger&lt;MyChildClass&gt;()</code> or</p></li>
  <li><p>pass parent controller's <strong><code>ILogger&lt;MyController&gt;</code></strong> to each child class
  created from the controller and having non-generic parameter ILogger.</p></li>
  </ul>
  
  <p>In logs I prefer to see separate category 'MyChildClass' for each class, rather than all classes use the category 'MyController' from the parent controller.<br>
  However CreateLogger in each object construction can be an expensive operation (e.g. see <a href="https://github.com/aspnet/Logging/issues/524" rel="noreferrer">https://github.com/aspnet/Logging/issues/524</a>) </p>
  
  <p>Which option will you  recommend? Can you suggest any other approach?</p>