31

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

JimmyShoe
  • 2,009
  • 4
  • 21
  • 40

2 Answers2

33

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/#hierarchical-configuration-data & https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/#non-prefixed-environment-variables

Chris DaMour
  • 3,650
  • 28
  • 37
18

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

Hope this helps!! Cheers!! :)

KrishnaG
  • 3,340
  • 2
  • 6
  • 16
  • 8
    Ah! It seems like it's a Linux-specific thing: `In a default Linux container or a custom Linux container, any nested JSON key structure in the app setting name like ApplicationInsights:InstrumentationKey needs to be configured in App Service as ApplicationInsights__InstrumentationKey for the key name. In other words, any : should be replaced by __ (double underscore).` – ataraxia Aug 26 '19 at 01:09
  • 14
    To be precise, both `:` (single colon) and `__` (double underscore) will work in Windows environments, only `__` will work in Linux. So for safety's sake, use `__`. – Ian Kemp Mar 26 '20 at 14:47
  • Double underscore and neither : works for me, – Zaha Apr 22 '22 at 17:45