我最近设置了Serilog来处理我对数据库的日志记录活动。但是,当我启动它时,我注意到许多System
和Microsoft
活动充满了行。我试图在我的Serilog过滤器中添加多个替代,但仍保留了诸如Executed action method和Db Command之类的替代。我需要重写什么才能从日志中删除它们?
我的appsettings.json
"Serilog": {
"MinimumLevel": "Information",
"Override": {
"Microsoft": "Error",
"Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory": "Error",
"Microsoft.EntityFrameworkCore.Database.Command": "Error",
"Microsoft.AspNetCore.Hosting.Internal.WebHost": "Error",
"ToDoApi": "Error",
"Engine": "Error",
"System": "Error"
},
答案 0 :(得分:0)
我发现了一种更好的方法。在我配置记录器的程序中:
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.Filter.ByExcluding(Matching.FromSource("Microsoft"))
.Filter.ByExcluding(Matching.FromSource("System"))
.Enrich.FromLogContext()
.CreateLogger();
这样,我可以控制要记录的内容。
答案 1 :(得分:0)
您的MinimumLevel
配置部分不太正确:Override
应该在它下面。您需要:
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Error",
"ToDoApi": "Error",
"Engine": "Error",
"System": "Error"
}
}
}