title: serilog async sink not flushing buffer to disk on shutdown
body: <p>When using the serilog async sink with the file sink (and buffered = true), log entries are being lost on shutdown. I'm guessing it's the buffer not flushing to disk, even though it is being called. I'm not sure why this is happening, but I'm pretty certain it's the async sink. If I remove it from the config and just use the file sink on its own, the log gets flushed to disk as expected. </p>
  
  <p>I've got a fairly simple setup. </p>
  
  <p>program.cs:</p>
  
  <pre><code> public class Program
  {
      public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
          .SetBasePath(Directory.GetCurrentDirectory())
          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
          .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
          .AddEnvironmentVariables()
          .Build();
  
      public static void Main(string[] args)
      {
  
          Log.Logger = new LoggerConfiguration()
              .ReadFrom.Configuration(Configuration)
              .CreateLogger();
  
          try
          {
              Log.Information("Starting the web host");
  
              CreateWebHostBuilder(args).Build().Run();
  
              Log.Information("Shutting down the web host");
  
          }
          catch (Exception ex)
          {
              Log.Fatal(ex, "Host terminated unexpectedly");
  
          }
          finally
          {
              Log.Information("Closing Log");
  
              Log.CloseAndFlush();
          }
  
  
  
      }
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()            
              .UseSerilog();
  
  }
  </code></pre>
  
  <p>appsettings.json</p>
  
  <pre><code>    {
    "Serilog": {
      "MinimumLevel": {
        "Default": "Debug",
        "Override": {
          "Microsoft": "Information",
          "System": "Warning"
        }
      }
    },
    ...
  </code></pre>
  
  <p>appsettings.Development.json</p>
  
  <pre><code>{
    "Serilog": {
      "WriteTo": [
        {
          "Name": "Async",
          "Args": {
            "configure": [
              {
                "Name": "Console",
                "Args": {
                  "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
                  "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} &lt;s:{SourceContext}&gt;{NewLine}{Exception}"
                }
              },
              {
                "Name": "File",
                "Args": {
                  "path": "logs/log.txt",
                  "formatter": "Serilog.Formatting.Json.JsonFormatter",
                  "rollingInterval": "Day",
                  "retainedFileCountLimit": 7,
                  "buffered": true
                }
              }
            ]
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>If I put a breakpoint on the Log.CloseAndFlush() line it'll hit it when shutting down, but it doesn't actually flush the buffer to disk.</p>
  
  <p>Any ideas? </p>