Serilog 过滤器未过滤 ResultDescription
我在使用 Serilog 过滤 ResultDescription 字段时遇到问题。可能是我做错了什么。 这是我的代码:
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(x => x.Logger( (configureLogger) =>
{
configureLogger.Filter.ByExcluding("ResultDescription like '%Tesz log%'");
}))
.WriteTo.Async(x => x.Console(
outputTemplate: "bla -> [{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
theme: AnsiConsoleTheme.Code))
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);
我还在 ByExclusion
中尝试了 lambda 表达式,但这也不起作用。 在我的控制器中,我正在测试以下内容:
public async Task<IActionResult> Test()
{
logger.LogInformation("Teszt log!"); //I don't want to see this logs
logger.LogInformation("I am logging!");
return Ok("Test log has benn colled.");
}
I have problem with filtering ResultDescription field with Serilog. It might be that I am doing something wrong.
Here is my code:
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(x => x.Logger( (configureLogger) =>
{
configureLogger.Filter.ByExcluding("ResultDescription like '%Tesz log%'");
}))
.WriteTo.Async(x => x.Console(
outputTemplate: "bla -> [{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
theme: AnsiConsoleTheme.Code))
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);
I also tried a lambda expression in ByExcluding
, but that didn't work either.
In my controller I am testing with the following:
public async Task<IActionResult> Test()
{
logger.LogInformation("Teszt log!"); //I don't want to see this logs
logger.LogInformation("I am logging!");
return Ok("Test log has benn colled.");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)