【发布时间】:2020-03-04 16:02:44
【问题描述】:
我在我的 ASP.NET Core Web 应用程序中使用 appsettings.json 为我的应用程序提供配置值。有些配置比单纯的“名称/值对”还要复杂,比如 Serilog 配置:
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore.Authentication": "Information"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "C:/Development/logs/log-auth.txt",
"fileSizeLimitBytes": 1000000,
"rollOnFileSizeLimit": true,
"shared": true,
"flushToDiskInterval": 1,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext} | {Message:lj}{NewLine}{Exception}"
}
}
]
}
我想知道的是,如何为我的 Azure Web 应用提供此配置?我知道我可以创建一个appsettings.Production.json 文件并在发布时推送它,但是使用发布部署设置有什么意义呢?它们也可能是硬编码的。设置文件的要点是您应该能够更改设置并重新启动应用程序,更改其行为,而无需重新部署代码。
我可以看到 Azure 提供的唯一内容是门户中的“设置|配置”部分,但这些设置只允许是简单的名称/值对。我的 Serilog 配置在那里无效。那么如何提供任何类型的高级配置呢?
【问题讨论】:
标签: c# azure asp.net-core