Merging appsettings with environment variables in .NET Core Merging appsettings with environment variables in .NET Core docker docker

Merging appsettings with environment variables in .NET Core


config.    AddJsonFile("appsettings.json").    AddJsonFile("appsettings.docker.json", true).    AddEnvironmentVariables();

is actually enough to override appsettings values using environment variables.

Let's say you have the following in your appsettings.json file;

{  "Logging": {      "Level": "Debug"  }}

you can override value of Logging.Level by setting the environment variable named Logging:Level to the value of your preference.

Be aware that : is used to specify nested properties in environment variable keys.

Also note: from docs;

If a colon (:) can't be used in environment variable names on your system, replace the colon (:) with a double-underscore (__).