Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

azure application settings - how to add nested item

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

like image 522
JimmyShoe Avatar asked Apr 03 '19 14:04

JimmyShoe


2 Answers

you use : to nest:keys:down

cross platform you use __ to nest__keys__down (since : are bad for envars in *nix)

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://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-3.1#hierarchical-configuration-data & https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-3.1#environment-variables-configuration-provider

like image 150
Chris DaMour Avatar answered Oct 19 '22 12:10

Chris DaMour


As per this article, you would have to use syntax something like "CustomSettings__MySpecificSetting".

Hope this helps!! Cheers!! :)

like image 38
KrishnaG-MSFT Avatar answered Oct 19 '22 12:10

KrishnaG-MSFT