title: .net core 2.2, Reading setting from user secrets for serilog
body: <p>I have set up my solution and serilog reads the values from appsettings.json</p>
  
  <pre><code>public void Configure(IApplicationBuilder application, IHostingEnvironment environment, ILoggerFactory loggerFactory)
  {
       Logger log = new LoggerConfiguration()
              .ReadFrom.Configuration(Configuration)
              .CreateLogger();
       loggerFactory.AddSerilog(log);
  </code></pre>
  
  <p>And the appsettings looks like this:</p>
  
  <pre><code> "Serilog": {
      "Using": [ "Serilog.Sinks.Slack", "Serilog.Sinks.ApplicationInsights" ],
      "MinimumLevel": {
        "Default": "Debug",
        "Override": {
          "Microsoft": "Error",
          "System": "Error"
        }
  
      },
      "WriteTo": [
        {
          "Name": "Slack",
          "Args": {
            "WebHookUrl": "https://hooks.slack.com/services/xxx/yyy/zzz",
            "CustomChannel": "#channel"
          }
        },
        {
          "Name": "ApplicationInsights",
          "Args": {
            "InstrumentationKey": "xxx-xxx-xxx-xxx-xxx",
            "restrictedToMinimumLevel": "Information",
            "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"
          }
        }
      ]
    }
  </code></pre>
  
  <p>So everything is fine til here, but I don't want to store secrets like webhook and InstrumentationKey in my repository. I want to read them from a safe place like user-secrets on development environment and Key-vault on prouction. How do I change it to replace the values from usersecrets?</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.2&amp;tabs=windows" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.2&amp;tabs=windows</a></p>
  
  <p>Is there anyways the config get overriten automatically?</p>
  
  <p>If not, I know I can read my configuration from secrets let's say like </p>
  
  <pre><code>  webHookUrl = Configuration["Serilog:WriteTo:Slack:WebHookUrl"];
  </code></pre>
  
  <p>But then how do I apply it on the loggerConfig? I mean, the writeTo part is dynamic from the settings, should I then add it in code instead? :\</p>
  
  <h2>Update</h2>
  
  <p>Since many people have asked, in my program.cs I have:</p>
  
  <pre><code>public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .UseApplicationInsights()
                  .UseStartup&lt;Startup&gt;();
  </code></pre>
  
  <p>And based on the Microsoft documentation, everything should work because I have <code>CreateDefaultBuilder</code> and I am running .net core 2.2.
  <a href="https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.2&amp;tabs=windows#access-a-secret" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.2&amp;tabs=windows#access-a-secret</a></p>
  
  <p>In ASP.NET Core 2.0 or later, <strong>the user secrets configuration source is automatically added in development mode when the project calls CreateDefaultBuilder</strong> to initialize a new instance of the host with preconfigured defaults. CreateDefaultBuilder calls AddUserSecrets when the EnvironmentName is Development.</p>
  
  <p>When CreateDefaultBuilder isn't called, add the user secrets configuration source explicitly by calling AddUserSecrets in the Startup constructor. Call AddUserSecrets only when the app runs in the Development environment</p>