Azure 应用程序设置 - 如何添加嵌套项

azure application settings - how to add nested item

我在 Azure 上有一个应用服务,它是 运行 一个 .net 核心 api。

在我的 appsettings.json 文件中,我有一个类似于以下内容的部分:

"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"          
    }
  }
]}

在 azure 门户的 azure appsetting 部分,我不确定如何设置 apiKey,在其他更简单的设置中,我在 appsettings.json[=13 中有另一个部分=]

 "CustomSettings": {    
    "MySpecificSetting": "ABCDEFG",    
  }

然后在 Azure 门户中,我可以通过执行以下操作来设置设置

CustomSettings:MySpecificSetting 

但我不确定这种语法如何允许我访问 writeTo 数组中的特定项目

感谢您的帮助

根据 this 文章,您必须使用类似于 "CustomSettings__MySpecificSetting".

的语法

希望对您有所帮助!!干杯!! :)

你使用 : 到 nest:keys:down

跨平台使用 __ 到 nest__keys__down(因为 : 在 *nix 中对 envars 不利)

关键是 azure 没有做任何特别的事情...azure 只是从那里为应用程序设置环境变量。它是 .net 核心配置,它实际上是在查看环境变量并做一些特殊的事情,请参阅 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