Advertisement
Intermediate .NET, Configuration & Options

How does appsettings.{Environment}.json layering work, and how is the current environment determined?

Short answer

ASP.NET Core loads appsettings.json first as a base configuration, then layers appsettings.{EnvironmentName}.json on top (where settings in the environment-specific file override matching keys from the base file), with the environment determined by the ASPNETCORE_ENVIRONMENT…

Save .NET mock interview
Advertisement
AModel answer
ASP.NET Core loads appsettings.json first as a base configuration, then layers appsettings.{EnvironmentName}.json on top (where settings in the environment-specific file override matching keys from the base file), with the environment determined by the ASPNETCORE_ENVIRONMENT environment variable (commonly Development, Staging, or Production), letting you maintain environment-specific overrides without duplicating the entire configuration file.
// appsettings.json (base, all environments)
{ "Logging": { "LogLevel": { "Default": "Information" } } }

// appsettings.Development.json (overrides base only in Development)
{ "Logging": { "LogLevel": { "Default": "Debug" } } }

// Set via: ASPNETCORE_ENVIRONMENT=Development
Real-world example
A team keeps verbose Debug-level logging enabled only in appsettings.Development.json, while production automatically uses the quieter Information-level default from the base appsettings.json, without any code changes between environments.
Likely follow-ups
  • How do you add a custom environment beyond the standard three?
  • What happens if ASPNETCORE_ENVIRONMENT isn't set at all?
Related topics