Im running a .net core console app, hosting the aspnet core runtime. There are 3 different environements I'm using - Debug, Dev and Prod and their associated appsettings json files. So I'm using a Startup class, but even before the Startup code is used, the WebhostBuilder is setup. From the docs:  

<https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.0>

> 
> If a value for the same key is set by the same or different
>  configuration providers, the last value set on the key is the value
>  used.
> 
> 
> 

Ok great, maybe I don't really understand how the correct settings get into the config object, but see below how I'm adding the root appsettings json file then the environment-specific one, and this ***seems*** to work.  

So at most, I should have TWO appsettings being referenced and the value 
However, later when the config object gets injected into one of the services in my Startup class, the value i'm trying to pull from the config object isn't there. Since my environment variable is Debug, it should be reading from the value in the appsettings.debug.json file

in appsettings.json

```
-not there-

```

in appsettings.debug.json

```
"AppSettings": {
  "CustomerFilesRoot": "\\\\dev-haulops1\\d$\\BoxFiles",

```

Also, when Im stepping into one of my services and looking at the config object that has been injected, I see 4 Json configuration providers? Why 4 instead of 2 ? Drilling down into these, there are 2 each from appsettings.debug.json and appsettings.json Hmmm strange. I'm obviously missing something.

[![enter image description here](https://i.stack.imgur.com/17dqE.png)](https://i.stack.imgur.com/17dqE.png)

In my Program.cs

```
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)                
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.AddEventLog();
                })
                .ConfigureAppConfiguration((context, config) =>
                {

                    // Configure the app here.
                    var env = context.HostingEnvironment;
                    config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);

                })
                .UseStartup<Startup>();

```

The beginnings of Startup.cs  

```
public IConfiguration Configuration { get; }
public IHostingEnvironment HostingEnvironment { get; }

public Startup(IConfiguration configuration, IHostingEnvironment environment)
{
    Configuration = configuration;
    HostingEnvironment = environment;
}

```

**[ update ]**  

Not sure if anyone noticed, Im using WebHost rather than Generic Host, so just like with a web app, there is no explicit need to "add" the appsettings files. Eg, in a web app I have. So, Im still scratching my head why within a console app that happens to be using the aspcore runtime and using WebHost that its not trying to use the file (at least for me) associated with the environment var that is set in the launchsettings.json file. When I take out the explicit loading of the two appsettings files, I get them loaded as configurationproviders at debugtime and I can see two (as opposed to 4 mentioned earlier). The problem is that when I go to extract a value from the config object, its giving me a value from the file that does not match the environment var.

```
    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

```