Let’s assume there is a .net web api application and that the developer wants to use a different value of a nested property than the one in application settings.

To override this property value in the Azure App Service, special attention needs to be given to how the key will be declared under the Configuration section for the nested application setting, as there is a small difference between the Windows and the Linux App Service.

In the Windows App Service Configuration, the : is used; on the other hand, in the Linux App Service Configuration, instead of the : (colon) the __(double underscore) has to be used for the nested application setting key.

So, in order to access the Default log level from a configuration file such as the following:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

the following can be used:

  • Logging:LogLevel:Defaultfor apps hosted on the Azure App Service on Windows
  • Logging__LogLevel__Defaultfor apps hosted on the Azure App Service on Linux

and then, in the code, that app settings value can be accessed as usual using _configuration.GetValue<string>("Logging:LogLevel:Default");

How to test it

The following example presents a very simple web api application that consists of a single SettingsController and a GET method that returns the Default log level from the application settings file:

To update the nested configuration property in the Configuration section on each Azure App Service, it’s important to remember that on Linux :must be changed to __(double underscore), as shown in the following picture:

After doing so, when the setting value is fetched from each web api, the appropriate result will appear based on the relevant settings:

  • `GET https://linux-sample-api.azurewebsites.net/api/settings` -> “Debug”
  • `GET https://windows-sample-api.azurewebsites.net/api/settings` -> “Debug”

instead of Information which is declared in the appsettings.json file.

Categorized in: