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

Jim*_*hoe 16 azure azureportal

我在 azure 上有一个运行 .net core api 的 appservice。

在我的 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"          
    }
  }
]}
Run Code Online (Sandbox Code Playgroud)

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

 "CustomSettings": {    
    "MySpecificSetting": "ABCDEFG",    
  }
Run Code Online (Sandbox Code Playgroud)

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

CustomSettings:MySpecificSetting 
Run Code Online (Sandbox Code Playgroud)

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

谢谢你的帮助

Chr*_*our 16

你使用 : 来嵌套:keys:down

您使用 __ 来嵌套 __keys__down 的跨平台(因为:对 *nix 中的 envar 不利)

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

  • 这对我有用,_但是_,我必须在保存后手动重新启动应用程序,即使保存对话框显示“这将重新启动应用程序”。对于这里遇到同样问题的任何人。 (2认同)
  • @Enrico 他们在 *nix 中不起作用 (2认同)

Kri*_*SFT 10

按照文章中,你将不得不使用的语法类似“CustomSettings__MySpecificSetting”。

希望这可以帮助!!干杯!!:)

  • 啊! 这似乎是 Linux 特定的事情:“在默认 Linux 容器或自定义 Linux 容器中,应用程序设置名称中的任何嵌套 JSON 密钥结构(例如 ApplicationInsights:InstrumentationKey)都需要在应用服务中配置为 ApplicationInsights__InstrumentationKey 作为密钥名称。换句话说,任何 : 都应该替换为 __ (双下划线)。 (7认同)
  • 准确地说,“:”(单冒号)和“__”(双下划线)都可以在 Windows 环境中使用,只有“__”可以在 Linux 环境中使用。所以为了安全起见,请使用`__`。 (7认同)