title: How to disable auto logging using Serilog in ASP.NET Core
body: <p>I would know if there's a way to disable auto-logging using <code>Serilog</code>.</p>
  <p>I installed it and the <code>sink</code> to handle logging using MSSqlServer.</p>
  <p><code>appsettings.json</code>:</p>
  <pre><code>{
    &quot;Serilog&quot;: {
      &quot;Using&quot;: [ &quot;Serilog.Sinks.MSSqlServer&quot; ],
      &quot;MinimumLevel&quot;: &quot;Information&quot;,
      &quot;WriteTo&quot;: [
        {
          &quot;Name&quot;: &quot;MSSqlServer&quot;,
          &quot;Args&quot;: {
            &quot;connectionString&quot;: &quot;Server=tcp:{ServerAddress};Initial Catalog={DBName};Persist Security Info=False;User ID={Username};Password={Password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;&quot;,
            &quot;sinkOptionsSection&quot;: {
              &quot;tableName&quot;: &quot;App_Logs&quot;,
              &quot;autoCreateSqlTable&quot;: true
            }
          }
        }
      ]
    },
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;Default&quot;: &quot;Trace&quot;,
        &quot;System&quot;: &quot;Information&quot;,
        &quot;Microsoft&quot;: &quot;Information&quot;
      }
    },
    // ...other configs
  }
  </code></pre>
  <p>then this is my config in <code>Progam.cs</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
      Host.CreateDefaultBuilder(args)
          .ConfigureWebHostDefaults(webBuilder =&gt; webBuilder.UseStartup&lt;Startup&gt;())
          .UseSerilog((hostingContext, loggerConfiguration) =&gt;
          {
              loggerConfiguration
                  .ReadFrom.Configuration(hostingContext.Configuration);
          });
  </code></pre>
  <p>In <code>Startup.cs</code> (now commented because i thought it was the cause of the auto loggin but also commenting it it auto-writes records on db):</p>
  <pre class="lang-cs prettyprint-override"><code>// enables Serilog's HTTP request logging. 
  // IMPORTANT: it won't log anything that appears *before* it in the pipeline, 
  // so be sure to add it *before* UseEndpoints(), UseMvc(), UseSpa() and so on.
  // app.UseSerilogRequestLogging();  &lt;------ i thought it was the cause of the auto loggin but also commenting it it auto-writes records on db
  </code></pre>
  <p>The logging action:</p>
  <pre><code>public MVCBaseController(
      ILogger&lt;TController&gt; logger,
      ...)
  {
      Logger = logger;
      // ...
  }
  
  public ILogger&lt;TController&gt; Logger { get; }
  // ...
  
  protected void LogInformation(string message)
  {
      string controllerName = ControllerContext?.ActionDescriptor?.ControllerName ?? string.Empty;
      string actionName = ControllerContext?.ActionDescriptor?.ActionName ?? string.Empty;
      string names = 
          $&quot;[{(!string.IsNullOrEmpty(controllerName) ? $&quot;{controllerName}&quot; : &quot;Controller name not found&quot;)}&quot; 
          + $&quot;{(!string.IsNullOrEmpty(actionName) ? $&quot;.{actionName}]&quot; : &quot;]&quot;)}&quot;;
  
      Logger.LogInformation($&quot;{names}\n{message}&quot;);
  }
  </code></pre>
  <p>It works but when i check the table i see a lot of records in addition to mine:
  <a href="https://i.stack.imgur.com/fcwh7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fcwh7.png" alt="db_result" /></a></p>
  <p>is there a way to tell Serilog to log only my handled logs?
  Thank you!</p>