Advertisement
Intermediate ASP.NET Core, Configuration & Options Pattern

How does appsettings.{Environment}.json layering work, and how does ASP.NET Core determine the current environment?

Short answer

ASP.NET Core loads appsettings.json first as a base configuration, then layers appsettings.{EnvironmentName}.json on top, overriding matching keys, with the environment determined by the ASPNETCORE_ENVIRONMENT environment variable (Development, Staging, Production) -- letting…

Save ASP.NET Core mock interview
Advertisement
AModel answer
ASP.NET Core loads appsettings.json first as a base configuration, then layers appsettings.{EnvironmentName}.json on top, overriding matching keys, with the environment determined by the ASPNETCORE_ENVIRONMENT environment variable (Development, Staging, Production) -- letting you maintain environment-specific overrides without duplicating the entire configuration file.
// appsettings.json (base)
{ "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 support for a custom environment name beyond the standard three?
  • What happens if ASPNETCORE_ENVIRONMENT isn't set at all?
Related topics