title: .Net 6.0 Configuration files
body: <p>Been getting a app that serves up data to a VBA application.  Now at point trying to get configuration files (appsettings.json &amp; appsettings.Development.Json). Right now it's a .net6.0 console app, later I'm making it an IconTrayApp.</p>
  <p>Ran into a problem, the main Program.cs method gets the appsettings.json and the worker gets the appssettings.Developement.json. I understand why Main() get the none environment json, because I explicitly load it.  But I want the app to use the same file both in an out of the IDE.</p>
  <p>here is program.cs</p>
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using PostDataService.InterfaceModels;
  using Serilog;
  using Serilog.Events;
  using System;
  
  namespace PostDataService
  {
    public class Program
    {
      public static void Main(string[] args)
      {
  
        var builder = new ConfigurationBuilder()
          .AddJsonFile(&quot;appsettings.json&quot;, optional: false, reloadOnChange: true);
        IConfiguration config = builder.Build();
        string _logFQN = config[&quot;PostConfig:Basefolder&quot;] + config[&quot;PostConfig:LogsFolder&quot;] + config[&quot;PostConfig:LogFname&quot;];
        string _LogTemplate = config[&quot;PostConfig:LogTemplate&quot;];
  
        var loggerConfig = new LoggerConfiguration()
          .MinimumLevel.Override(&quot;Microsoft&quot;, LogEventLevel.Verbose)
          .Enrich.FromLogContext()
          .Enrich.WithThreadId()
          .Enrich.WithEnvironmentUserName()
          .WriteTo.File(_logFQN,
          fileSizeLimitBytes: 524288000,
          rollOnFileSizeLimit: true,
          rollingInterval: RollingInterval.Day,
          outputTemplate: _LogTemplate);
  
        Log.Logger = loggerConfig.CreateLogger();
        try
        {
          Log.Write(LogEventLevel.Information, &quot;Start USPS Data Server&quot;);
          CreateHostBuilder(args).Build().Run();
        }
        catch (Exception ex)
        {
          Log.Fatal(ex, &quot;Host terminated unexpectedly&quot;);
        }
        finally
        {
          Log.Information(&quot;USPS Server stopped&quot;);
          Log.CloseAndFlush();
        }
      }
  
      public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .UseSerilog()
              .ConfigureServices((hostContext, services) =&gt;
              {
                IConfiguration configuration = hostContext.Configuration;
                WorkerOptions options = configuration.GetSection(&quot;PostConfig&quot;).Get&lt;WorkerOptions&gt;();
                services.AddSingleton(options);
                services.AddHostedService&lt;Worker&gt;();
              });
  
    }
  }
  </code></pre>
  <p>and here is appsettings.json (appsettings.Development.json)</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;PostConfig&quot;: {
      &quot;BaseFolder&quot;: &quot;./App_Data/&quot;,
      &quot;LogsFolder&quot;: &quot;logs/&quot;,
      &quot;SystemFQN&quot;: &quot;C:/Test/PostalDB/PostalData.db&quot;,
      &quot;CustFQN&quot;: &quot;C:/Test/PostalDB/PostalCustomer.db&quot;,
      &quot;LogFname&quot;: &quot;USPS_.log&quot;,
      &quot;LogTemplate&quot;: &quot;{Timestamp:yyyy-MM-dd HH:mm:ss.fff}\t{EnvironmentUserName}\t[{Level:u4}]\t&lt;{ThreadId}&gt;\t{Message:lj}{NewLine}{Exception}&quot;
    }
  }
  </code></pre>
  <p>I did try and use the .AddEnvironmentVariables() in the configuration builder and that did not seem to change things. I suspect because of the explicit addjsonfile call.</p>