title: Pass Ilogger on non-controller models
body: <p>I am creating an app in .net core and I'm trying to output a log.</p>
  
  <p>I was able to log output from the controller and I also want to log output from the model, which is shown below.</p>
  
  <p>Unfortunately, I don't know what to pass as arguments to the constructor. My guess is the same <code>Ilogger&lt;controller&gt;</code> as the controller, but I would like to know if there is a correct way.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Controller:</p>
  
  <pre><code>public class SampleController : Controller {
      public readonly ILogger&lt;SampleController &gt; _logger;
      public SampleController (ILogger&lt;SampleController &gt; logger)
      {
          _logger = logger;
      }
  
  
      [HttpGet("[action]")]
      public string FindSample()
      {
          _logger.LogInformation("FindSample Start");
  
          // ***** Is it necessary to carry over the log of the sample controller to a much lower DAO from here? *****
          var model = new SampleModel(_logger);
          var result = model.Find();
  
          _logger.LogInformation("FindSample End");
          return result;
      }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>    public class SampleModel
      {
          public readonly ILogger&lt;SampleController&gt; _logger;
          public SampleModel(ILogger&lt;SampleController&gt; logger)
          {
              _logger = logger;
          }
  
          public string Find()
          {
              _logger.LogInformation("FindModel Start");
  
              var dao = new SampleDao(_logger);
              var code = dao.GetCode();
  
              _logger.LogInformation("FindModel End");
              return code;
          }
      }
  </code></pre>
  
  <p>Dao:</p>
  
  <pre><code>    public class SampleDao
      {
          public readonly ILogger&lt;SampleController&gt; _logger;
          public SampleContext SampleContext;
  
          // ***** Should I pass it as an argument forever? *****
          public SampleDao(ILogger&lt;SampleController&gt; logger)
          {
              _logger = logger;
              if (SampleContext == null)
              {
                  SampleContext = new SampleContext();
              }
          }
  
          public string GetCode()
          {
              _logger.LogInformation("GetCode Start");
  
              var code = SampleContext.SampleTable.FirstOrDefault().code;
  
              _logger.LogInformation("GetCode End");
              return code;
          }
      }
  
  </code></pre>