title: How to use Serilog in .NET Core Console app
body: <p>I wanted my application to have capability of logging to a file, so I started to look for something more than default .NET Core 2.2 logging framework. I see that Serilog might do the job. However, I cannot find any document on how to setup Serilog in .NET Core Console application with Dependency Injection. All I see is ASP.NET materials, which is probably not what I need.</p>
  
  <p>I started doing it myself. I installed (Nuget): </p>
  
  <ul>
  <li>Serilog</li>
  <li>Serilog.Extensions.Logging</li>
  <li>Serilog.Sinks.File</li>
  <li>Serilog.Sinks.Console (to use Serilog for all my logging)</li>
  </ul>
  
  <p>I created an extension for<code>ServiceCollection</code></p>
  
  <pre class="lang-cs prettyprint-override"><code>        public static void AddLogging(this IServiceCollection services, Microsoft.Extensions.Logging.LogLevel logLevel)
          {
              var serilogLogger = new LoggerConfiguration()
              .WriteTo.Console()
              .WriteTo.File("log.txt")
              .CreateLogger();
  
              services.AddLogging(builder =&gt;
              {
                  builder.SetMinimumLevel(logLevel);
                  builder.AddSerilog(logger: serilogLogger, dispose: true);
              });
          }
  </code></pre>
  
  <p>Logging works, however:</p>
  
  <ul>
  <li>log level is not what I set it to. It seems that serilog is using INFO level, although I wanted to have DEBUG. Why isn't my setting respected? After all, I'm still using NET Core's logging framework, so I'm using it to setup the log level</li>
  <li>am I actually doing this setup correctly? I am not really sure if <code>dispose</code> should be <code>true</code>. Generally, I want NET Core's Dependency Injection framework to take care of disposal of services.</li>
  </ul>