title: Serilog config in appsettings.json for an ASP.NET CORE application
body: <h2>Disclaimer</h2>
  <p>I know there are several similar questions posted about this subject, but I couldn't find one that exactly represented the problems I'm experiencing. That's why I'm opening a new question.</p>
  <h2>Current situation</h2>
  <p>I have an ASP.NET CORE API application build using VS2019 where I want to use Serilog for logging to a database server. To achieve this, I'm using some of the available Serilog NuGet packages</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;PackageReference Include=&quot;Serilog&quot; Version=&quot;2.10.0&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.AspNetCore&quot; Version=&quot;4.1.0&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Exceptions&quot; Version=&quot;6.1.0&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Exceptions.EntityFrameworkCore&quot; Version=&quot;6.1.0&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Extensions.Logging&quot; Version=&quot;3.0.1&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Settings.Configuration&quot; Version=&quot;3.1.0&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Sinks.Console&quot; Version=&quot;3.1.1&quot; /&gt;
  &lt;PackageReference Include=&quot;Serilog.Sinks.MSSqlServer&quot; Version=&quot;5.6.0&quot; /&gt;
  </code></pre>
  <p>This application uses 4 build configurations: 'Develop', 'Test', 'Acceptance' and 'Production'</p>
  <p>For setting up Serilog so I can use it in my application I've done the following in the Program.cs</p>
  <pre class="lang-c# prettyprint-override"><code>public class Program
  {
      public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
          [...]
          .AddJsonFile(&quot;appsettings.json&quot;, optional: false, reloadOnChange: true)
          .AddJsonFile($&quot;appsettings.{Environment.GetEnvironmentVariable(&quot;ASPNETCORE_ENVIRONMENT&quot;)}.json&quot;, optional: true)
          .Build();
  
      public static void Main(string[] args)
      {
          Log.Logger = new LoggerConfiguration()
              .ReadFrom.Configuration(Configuration)
              .Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
                .WithDefaultDestructurers()
                .WithDestructurers(new[] { new DbUpdateExceptionDestructurer() })
                .WithFilter(new IgnorePropertyByNameExceptionFilter(&quot;StackTrace&quot;)))
              .Enrich.WithProperty([...])
              .WriteTo.Console()
              .CreateLogger();
  
          [...]
      }
  
      public static IWebHost BuildWebHost(string[] args) =&gt; WebHost.CreateDefaultBuilder(args)
          .UseStartup&lt;Startup&gt;()
          .UseConfiguration(Configuration)
          .UseSerilog()
          .Build();
  }
  </code></pre>
  <p>And the appsettings.*.json:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;Serilog&quot;: {
      &quot;MinimumLevel&quot;: &quot;Warning&quot;,
      &quot;WriteTo&quot;: [
        {
          &quot;Name&quot;: &quot;MSSqlServer&quot;,
          &quot;Args&quot;: {
            &quot;connectionString&quot;: [...],
            &quot;tableName&quot;: [...],
            &quot;autoCreateSqlTable&quot;: false,
            &quot;columnOptionsSection&quot;: {
              [...]
            }
          }
        }
      ]
    }
  }
  </code></pre>
  <p>And the launchsettings.json:</p>
  <pre class="lang-json prettyprint-override"><code>{
    [...]  
    &quot;profiles&quot;: {
      &quot;Develop&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      },
      &quot;Test&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Test&quot;
        }
      },
      &quot;Acceptance&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Acceptance&quot;
        }
      },
      &quot;Production&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Production&quot;
        }
      }
    }
  }
  </code></pre>
  <p>[edit]
  All of the appsettings files (appsettings.json as well as all the appsettings.*.json) have these properties</p>
  <p><a href="https://i.stack.imgur.com/2o7ij.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2o7ij.png" alt="enter image description here" /></a></p>
  <h2>The challenges I'm facing</h2>
  <p>When I'm running the application locally on my machine (using the Develop build configuration), all works as expected. Logging is working well and logging to my develop SQL server.</p>
  <p>The issues start when I'm using TFS to deploy the application to a remote machine. Whether I'm deploying to my Development server or Test server, the logging is not working. The appsetting.json, as well as the appsetting.*.json files are deployed to the server correctly. When I'm manually copying the settings from the appropriate appsettings.*.json to the appsettings.json, everything works as expected. The logging is be done in the correct SQL database. Therefore I know the settings are correct. It just looks like my deployment is somehow only picking up the settings from the appsettings.json, not including the settings from the appsettings.*.json. I must be overlooking something, but I can't see what. Hopefully someone can help me with this.</p>