title: How to test asp.net core built-in Ilogger
body: <p>I want to verify some logs logged. I am using the asp.net core built-in ILogger, and inject it with the asp.net core built-in DI:   </p>
  
  <pre><code>private readonly ILogger&lt;InvoiceApi&gt; _logger;
  
  public InvoiceApi(ILogger&lt;InvoiceApi&gt; logger)
  {
      _logger = logger;
  }
  </code></pre>
  
  <p>then I use it like: <code>_logger.LogError("error));</code></p>
  
  <p>I tried to mock it (with moq) as usual by: </p>
  
  <pre><code>MockLogger = new Mock&lt;ILogger&lt;InvoiceApi&gt;&gt;();
  </code></pre>
  
  <p>and inject this in the service for test by: </p>
  
  <pre><code>new InvoiceApi(MockLogger.Object);
  </code></pre>
  
  <p>then tried verify:</p>
  
  <pre><code>MockLogger.Verify(m =&gt; m.LogError(It.Is&lt;string&gt;(s =&gt; s.Contains("CreateInvoiceFailed"))));
  </code></pre>
  
  <p>but it throw: </p>
  
  <blockquote>
    <p>Invalid verify on a non-virtual (overridable in VB) member: m => m.LogError</p>
  </blockquote>
  
  <p>So, how can I verify this logs logged?</p>