ASP.NET Core Interview Question #28

How do environment-specific appsettings files work?

Application Structure & Configuration Junior Beginner

Quick Interview Answer

ASP.NET Core can load configuration files for the current hosting environment. A typical application has appsettings.json plus files such as appsettings.Development.json, appsettings.Staging.json, and appsettings.Production.json.

Detailed Explanation

ASP.NET Core can load configuration files for the current hosting environment. A typical application has appsettings.json plus files such as appsettings.Development.json, appsettings.Staging.json, and appsettings.Production.json.

The environment-specific file is loaded after appsettings.json, so matching settings override the base values. This allows development and production to use different logging levels, service endpoints, or other environment-dependent settings without changing application code.

The active environment is commonly determined by the DOTNET_ENVIRONMENT or ASPNETCORE_ENVIRONMENT environment variable.

Code Example

// appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  }
}

// appsettings.Development.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    }
  }
}