问题
i have a appservice on azure that is running a .net core api.
in my appsettings.json file i have a section something similar to :
"Serilog": {
"LevelSwitches": { "$controlSwitch": "Information" },
"MinimumLevel": {
"ControlledBy": "$controlSwitch",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "LOGS\\log.json",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
},
{
"Name": "Seq",
"Args": {
"serverUrl": "https://MyLoggingServer",
"apiKey": "AAAAAAAAAAAAAAAAA",
"controlLevelSwitch": "$controlSwitch"
}
}
]}
In azure appsetting section on the azure portal i'm not sure how i would go about setting the apiKey, in other more simple settings i have another section in appsettings.json
"CustomSettings": {
"MySpecificSetting": "ABCDEFG",
}
Then in azure portal i have been able to set the setting by doing the following
CustomSettings:MySpecificSetting
but i'm not sure how this syntax would allow me to access the specific item in the writeTo array
Thanks for any help
回答1:
you use : to nest:keys:down
the key thing is it's not azure doing anything special... azure just sets env vars for the app from there. it's .net core config that's actually looking at the env vars and doing special things see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-3.1#hierarchical-configuration-data & https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-3.1#environment-variables-configuration-provider
回答2:
As per this article, you would have to use syntax something like "CustomSettings__MySpecificSetting".
Hope this helps!! Cheers!! :)
来源:https://stackoverflow.com/questions/55497468/azure-application-settings-how-to-add-nested-item