title: Unable to suppress Microsoft logs with NLog for API calls using HttpClient
body: <p>I have implemented NLog for .NET Core 3.1 MVC web app and API projects. The <code>nlog.config</code> file for both of them is nearly identical. I've carefuly checked this and the only difference is the database table name and file name that they log to.</p>
  <p>I'm successfully suppressing non-essential Microsoft logs from the API project, but am only partially able to do so for the web app. Specifically, Trace and Info logs by Microsoft that deal with making calls to the API using <code>HttpClient</code> appear in the file and database:
  <a href="https://i.stack.imgur.com/AsHrR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AsHrR.png" alt="photo of database table data showing microsoft logs that should not be there" /></a>
  You can see that only one of the logs is a log that I actually wrote, and the rest are were automatically logged by Microsoft.</p>
  <p>I'm not sure what to try here, but I've looked at the internal logs and saw nothing out of the ordinary.</p>
  <p>I want to know how can I suppress the additional Microsoft logs and what's wrong with my current configuration?</p>
  <p>NuGet packages I have installed (identical for both apps):
  <a href="https://i.stack.imgur.com/cGxJ1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cGxJ1.png" alt="Picture showing NuGet packages and their versions I have installed: NLog-4.7.6, NLog.Extensions.Logging-1.6.5, NLog.Schema-4.7.6, NLog.Web.AspNetCore-4.9.3" /></a></p>
  <p>nlog.config of the web app project:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;nlog xmlns=&quot;http://www.nlog-project.org/schemas/NLog.xsd&quot;
        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        autoReload=&quot;true&quot;
        throwConfigExceptions=&quot;true&quot;
        internalLogLevel=&quot;Info&quot;
        internalLogFile=&quot;c:\temp\internal-CNC_WebUI-nlog.txt&quot;&gt;
  
    &lt;extensions&gt;
      &lt;add assembly=&quot;Nlog.Extensions.Logging&quot;/&gt;
      &lt;add assembly=&quot;NLog.Web.AspNetCore&quot;/&gt;
    &lt;/extensions&gt;
  
    &lt;targets&gt;
      &lt;target xsi:type=&quot;File&quot; name=&quot;CNC_WebUIFile&quot; fileName=&quot;c:\temp\nlog-CNC_WebUIFile-${shortdate}.log&quot;
              layout=&quot;${aspnet-traceidentifier}|${configsetting:AppSettings.NlogConnection.AppName}|${event-properties:ObjectID}|${date}|${uppercase:${level}}|${message} ${exception:format=tostring}|${logger}|${callsite:filename=false}|${exception:toString}&quot; /&gt;
  
      &lt;target name=&quot;databaseLogger&quot; xsi:type=&quot;Database&quot;
            dbProvider=&quot;sqlserver&quot;
            dbHost=&quot;${configsetting:AppSettings.NlogConnection.DbHost}&quot;
            dbDatabase=&quot;${configsetting:AppSettings.NlogConnection.Database}&quot;
            dbUserName=&quot;${configsetting:AppSettings.NlogConnection.User}&quot;
            dbPassword=&quot;${configsetting:AppSettings.NlogConnection.Password}&quot; &gt;
  
        &lt;commandText&gt;
          INSERT INTO dbo.CNC_WebUILogs (
          CorrelationId, Application, ObjectID, Logged, Level, Message,
          Logger, CallSite, Exception
          ) VALUES (
          @CorrelationId, @Application, @ObjectID, @Logged, @Level, @Message,
          @Logger, @Callsite, @Exception
          );
        &lt;/commandText&gt;
        &lt;parameter name=&quot;@correlationId&quot; layout=&quot;${aspnet-traceidentifier}&quot; /&gt;
        &lt;parameter name=&quot;@application&quot; layout=&quot;${configsetting:AppSettings.NlogConnection.AppName}&quot; /&gt;
        &lt;parameter name=&quot;@ObjectID&quot; layout=&quot;${event-properties:ObjectID}&quot; /&gt;
        &lt;parameter name=&quot;@logged&quot; layout=&quot;${date}&quot; /&gt;
        &lt;parameter name=&quot;@level&quot; layout=&quot;${level}&quot; /&gt;
        &lt;parameter name=&quot;@message&quot; layout=&quot;${message}&quot; /&gt;
        &lt;parameter name=&quot;@logger&quot; layout=&quot;${logger}&quot; /&gt;
        &lt;parameter name=&quot;@callSite&quot; layout=&quot;${callsite:filename=false}&quot; /&gt;
        &lt;parameter name=&quot;@exception&quot; layout=&quot;${exception:toString}&quot; /&gt;
      &lt;/target&gt;
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;logger name=&quot;Microsoft.*&quot; levels=&quot;Warn,Error,Fatal&quot; writeTo=&quot;databaseLogger,CNC_WebUIFile&quot;&gt;&lt;/logger&gt;
      &lt;logger name=&quot;Microsoft.*&quot; minlevel=&quot;Trace&quot; final=&quot;true&quot; /&gt;
  
      &lt;logger name=&quot;*&quot; minlevel=&quot;Trace&quot; writeTo=&quot;CNC_WebUIFile&quot; /&gt;
      &lt;logger name=&quot;*&quot; minlevel=&quot;${configsetting:AppSettings.NlogConnection.LogLevel}&quot; writeTo=&quot;databaseLogger&quot; /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  <p>One of my repos that had their API call activity logged by Microsoft:</p>
  <pre><code>public class MfgrRepo : IMfgrRepo
  {
      private readonly IHttpClientFactory _clientFactory;
  
      public MfgrRepo(IHttpClientFactory clientFactory)
      {
          _clientFactory = clientFactory;
      }
  
      public async Task&lt;List&lt;MfgrDto&gt;&gt; Get()
      {
          HttpClient client = _clientFactory.CreateClient(HttpClientConfigNames.CNC);
  
          List&lt;MfgrDto&gt; models = new List&lt;MfgrDto&gt;();
          try
          {
              HttpResponseMessage response = await client.GetAsync(&quot;api/Mfgrs&quot;);
              models.AddRange(await response.Content.ReadFromJsonAsync&lt;List&lt;MfgrDto&gt;&gt;());
          }
          catch (Exception ex)
          {
              throw ex;
          }
  
          return models;
      }
  }
  </code></pre>