lon*_*nix 10 serilog asp.net-core asp.net-core-2.1
在代码、 xml 和json中有“全局”覆盖 MaximumLevel 的文档。
但是我可以使用 覆盖特定接收器appsettings.json吗?例如,我想以警告级别记录 class MyClass,但仅限于控制台接收器。
vla*_*mir 10
只需在特定接收器的配置部分中使用restrictedToMinimumLevel参数即可:
{
/* .. */
"Serilog": {
"MinimumLevel": {
"Default": "Verbose", /* <-- set the default level to the LOWEST applicable for your app */
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme::Literate, Serilog.Sinks.Console",
"restrictedToMinimumLevel": "Information" /* <-- set the minimum level for specific sink */
}
},
{
"Name": "File",
"Args": {
/* .. */
"restrictedToMinimumLevel": "Warning" /* <-- set the minimum level for specific sink */
}
},
{
"Name": "Udp",
"Args": {
/* .. */
"restrictedToMinimumLevel": "Warning" /* <-- set the minimum level for specific sink */
}
}
],
/* .. */
}
}
Run Code Online (Sandbox Code Playgroud)
我对这个问题也很感兴趣。我找不到解决办法。显然这不能正确完成。结果可能是这样的:
项目清单
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var logger = new LoggerConfiguration().ReadFrom.ConfigurationSection(_configuration.GetSection("Serilog"))
.ReadFrom.ConfigurationSection(_configuration.GetSection("SerilogLow")).CreateLogger();
services.AddSingleton<ILogger>(logger);
}
Run Code Online (Sandbox Code Playgroud)
华泰
| 归档时间: |
|
| 查看次数: |
4503 次 |
| 最近记录: |