简体   繁体   中英

How can I override all array properties in appsettings.json at once

I know that using appsettings.Development.json files we can overide default settings. Also I know that we can change single properties in json array using array:i incidator.

The question is, is it possible to override all json values at once. Like in example below for loggin rules?

appsettings.Development.json

...
  "NLog": {
...
    "rules": [
      {
        "logger": "*",
        "minLevel": "Info",
        "writeTo": "logconsole"
      },
      {
        "logger": "*",
        "minLevel": "Error",
        "writeTo": "allfile"
      }
    ]
...

Example solution appsettings.Development.json

{
  "NLog": {
    "rules:*": {
      "minLevel": "Error"
    }
  }
}

With NLog ver. 4.6.7 you don't have to override all array-properties. You can use NLog Config variables as minLevel in the rules-section. Ex:

{
  "NLog": {
    "variables": {
      "MinLevelInfo": "Info"
      "MinLevelError": "Error"
    },
    "rules": [
      {
        "logger": "*",
        "minLevel": "${MinLevelInfo}",
        "writeTo": "logconsole"
      },
      {
        "logger": "*",
        "minLevel": "${MinLevelError}",
        "writeTo": "allfile"
      }
    ]
  }
}

Example override in appsettings.Development.json

{
  "NLog": {
    "variables": {
      "MinLevelInfo": "Debug"
      "MinLevelError": "Debug"
    }
}

Now you just have to override NLog variables, and they will be automatically applied by NLog. See also https://github.com/NLog/NLog/pull/2709 and https://github.com/NLog/NLog/pull/3184

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM