title: ASP.NET Core 2.0 using Serilog to log stacktrace when exception is thrown
body: <p>So I've recently started to build a asp.net core application and for the logging i'm using SeriLog. This was working fine until recently I found out that most of the time the stacktrace of an exception is not being transferred to my logs. I'm using the .WriteTo.RollingFile() method to write to a .txt file in my LoggerConfiguration in Startup.cs like so</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      //add a bunch of services
  
      services.AddLogging(builder =&gt;
      {
          builder.AddConsole();
          builder.AddDebug();
  
          var logger = new LoggerConfiguration()
              .MinimumLevel.Verbose()
              .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
              .Enrich.WithExceptionDetails()
              .WriteTo.RollingFile(Configuration.GetValue&lt;string&gt;("LogFilePath") + "-{Date}.txt", LogEventLevel.Information,
                  outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
              .CreateLogger();
  
          builder.AddSerilog(logger);
      });
  
      services.AddMvc();
  }
  </code></pre>
  
  <p>And in my loggerFactory I added the Serilog with this line of code</p>
  
  <pre><code>loggerFactory.AddSerilog();
  </code></pre>
  
  <p>My BuildWebHost method does not have the .UserSerilog() and looks like this:</p>
  
  <pre><code>public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .Build();
  </code></pre>
  
  <p>This method gets called as the last step in my <code>Main</code> method in Program.cs
  Reading Serilog's documentation the {Exception} in the outputTemplate of the RollingFile should also log the stacktrace of the exception. However when for example I log an error like so (using the <code>Microsoft.Extensions.Logging.ILogger</code>)</p>
  
  <pre><code>_log.LogError("Exception thrown when trying to convert customer viewmodel to model or getting data from the database with id: " + id, ex);
  </code></pre>
  
  <p>This logs:</p>
  
  <pre><code>2017-12-12 10:59:46.871 +01:00 [Error] (ProjectName.Controllers.CustomersController) Exception thrown when trying to convert customer viewmodel to model or getting data from the database with id: 137dfdc1-6a96-4621-106c-08d538a26c5b
  </code></pre>
  
  <p>It does not have a stacktrace. But when for example I forget to inject a class into the constructor of a class through constructor injection from my .addServices it does log the stacktrace. For example:</p>
  
  <pre><code>2017-12-12 11:03:23.968 +01:00 [Error] (Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware) An unhandled exception has occurred while executing the request
  System.InvalidOperationException: Unable to resolve service for type 'TypeName' while attempting to activate 'ProjectName.Controllers.CustomersController'.
     at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
     at lambda_method(Closure , IServiceProvider , Object[] )
  </code></pre>
  
  <p>How do I get the stacktrace to show up in my logging .txt file?</p>