更新时间:2023-02-15 17:28:43
config.
AddJsonFile("appsettings.json").
AddJsonFile("appsettings.docker.json", true).
AddEnvironmentVariables();
实际上足以使用环境变量覆盖应用设置值.
is actually enough to override appsettings values using environment variables.
假设您的appsettings.json文件中包含以下内容;
Let's say you have the following in your appsettings.json file;
{
"Logging": {
"Level": "Debug"
}
}
您可以通过将名为Logging:Level
的环境变量设置为您的首选项值来覆盖Logging.Level
的值.
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;
如果不能在系统的环境变量名称中使用冒号(:),请用双下划线(__)替换冒号(:).