提问人:Khandakar Rashed Hassan 提问时间:4/22/2022 更新时间:4/22/2022 访问量:1092
Serilog 配置读取取决于 .Net 5 中辅助角色服务中的 Environment 变量
Serilog configuration read depending on the Environment variable in Worker service in .Net 5
问:
我根据 Environment 变量对 Serilog 有不同的配置。它们是用appsettings.json和appsetting编写的。Development.json.我的问题是在配置记录器时,它不会从应用程序设置中读取。即使在开发模式下Development.json。
我试过这样配置它,
.ConfigureAppConfiguration((w, c) =>
{
var env = w.HostingEnvironment;
if (env.EnvironmentName == "Development")
{
c.AddCustomJsonFile($"appsettings.{env.EnvironmentName}.json");
}
else
{
c.AddCustomJsonFile($"appsettings.json");
}
})
.ConfigureServices((hostContext, services) =>
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(hostContext.Configuration)
.CreateLogger();
}).UseSerilog();
而我的appsettings.json是这样的,
"Serilog": {
"MinimumLevel": {
"Defult": "Information",
"Override": {
"Micorsoft": "Warning",
"System": "Information"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341/"
}
}
]
并在 appsetting 中。Development.json,
"Serilog": {
"MinimumLevel": {
"Defult": "Debug",
"Override": {
"Micorsoft": "Warning",
"System": "Information"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341/"
}
}
]
我已经使用其他服务对其进行了测试,它使用基于环境变量的正确应用程序设置,Just Serilog 对此有问题。有人知道如何解决这个问题吗? 提前致谢。
答: 暂无答案
评论