在 appsettings.Prodution.json 中通过 "WriteTo": [ null ]
{
"Serilog": {
"WriteTo": [ null ]
}
}
覆盖 appsettings.json 中的下面 Serilog 的 WriteTo 配置,之前是可以的
{
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] {Message}{NewLine}{RequestPath}{NewLine}{SourceContext}{NewLine}{Exception}"
}
}
]
}
}
后来 serilog 的升级中不知道哪个版本造成 "WriteTo": [ null ] 不起作用,serilog 依然将日志写入控制台
也有可能是升级到 .NET 10 引起的
[ null ] 的解决方法见之前的博问 https://q.cnblogs.com/q/142479
这个问题就是如何在 appsettings.json 的配置项中覆盖一个数组
原来是 .NET 10 的一个 breaking change 引起的,详见 Null values preserved in configuration
解决方法:将 [ null ] 改为 [ "" ] 即可
{
"Serilog": {
"WriteTo": [ "" ]
}
}
Default configuration array merging is confusing and error-prone
– dudu 1周前How to override an ASP.NET Core configuration array setting reducing length of the array
– dudu 1周前