Back to results for “Logging”
.NET › Configuration & Options

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

Intermediate

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.

Common follow-ups: How do you add a custom environment beyond the standard three?;What happens if ASPNETCORE_ENVIRONMENT isn't set at all?