title: Serilog not writing to the file with Configuration loaded from appsettings.json in Console CORE 3 App
body: <pre><code>ASP.NET CORE 3.1 Worker Service Application.
  
  Packages
  
  "Microsoft.EntityFrameworkCore.Design" Version="3.1.3"
  
  PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3"
  
  PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.3"
  
  PackageReference Include="Serilog.AspNetCore" Version="3.2.0"
  
  PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0"
  </code></pre>
  
  <p>Serilog writing to the file with hard-coded LoggerConfiguration but not working from Config loaded from appsettings.json</p>
  
  <p>Here is application code</p>
  
  <pre><code>public static class Program
  {
      public static IConfigurationRoot Configuration { get; set; }
      private static string _environmentName;
  
      public static void Main(string[] args)
      {
          var hostBuilder = CreateHostBuilder(args).Build();
          //Log.Logger = (Configuration["Logging:LogLevel:Default"] == "Debug")? 
          //    new LoggerConfiguration()
          //    .MinimumLevel.Debug()
          //    .WriteTo.Console()
          //    .WriteTo.File(path: Path.Combine("C:/LogFiles", "OA-EmailService-.log"),
          //        rollingInterval: RollingInterval.Day, shared: true, flushToDiskInterval: TimeSpan.FromSeconds(10))
          //    .CreateLogger()
          //    :
          //    new LoggerConfiguration()
          //        .WriteTo.Console()
          //        .WriteTo.File(path: Path.Combine("C:/LogFiles", "OA-EmailService-.log"),
          //            rollingInterval: RollingInterval.Day, shared: true, flushToDiskInterval: TimeSpan.FromSeconds(10))
          //        .CreateLogger()
          //    ;
          Log.Logger = new LoggerConfiguration()
              .ReadFrom.Configuration(Configuration)
              .CreateLogger();
  
          try
          {
              Log.Information("APP:App started");
              hostBuilder.Run();
          }
          catch (Exception ex)
          {
              Log.Fatal(ex, "APP:App startup failed");
          }
          finally
          {
              Log.CloseAndFlush();
          }
      }
  
      public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureLogging((hostingContext, config) =&gt;
              {
                  config.ClearProviders();  //Disabling default integrated logger
                  _environmentName = hostingContext.HostingEnvironment.EnvironmentName;
              })
              .ConfigureAppConfiguration((hostingContext, config) =&gt;
              {
                  Configuration = new ConfigurationBuilder()
                      .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                      //.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json",
                      //    optional: false, 
                      //    reloadOnChange: true)
                      .AddEnvironmentVariables()
                      .Build();
              })
              .UseSerilog()
              .UseWindowsService()
              .ConfigureServices((hostContext, services) =&gt; { services.AddHostedService&lt;Worker&gt;(); });
  }
  </code></pre>
  
  <p>Here is appsettings.json</p>
  
  <pre><code>    {
        "Serilog": {
          "MinimumLevel": "Debug",
          "WriteTo": [
            {
              "Name": "Console",
              "Args": {
                "outputTemplate": "===&gt; {Timestamp:HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
              }
            },
            {
              "Name": "RollingFile",
              "Args": {
                "pathFormat": "C:/LogFiles/OA-EmailService-.log",
                "outputTemplate": "===&gt; {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
              }
            }
          ]
        }
      }
  </code></pre>
  
  <p>Interestingly that the part for Console sink is working well, it is just problem with file. How can I force serilog to write into the file?</p>