[英]Serilog .NET core: Filter Request logging and send them to a separate sink
I want to keep my requests logs on a separate log file.我想将我的请求日志保存在单独的日志文件中。 I cannot seem to find a way to filter Requests login traces
app.UseSerilogRequestLogging();
我似乎找不到过滤请求登录跟踪的方法
app.UseSerilogRequestLogging();
. .
Is there any way of achieving this?有没有办法实现这一目标? I do not find any documentation.
我没有找到任何文档。
This is the API I am trying to use, although I do not find any property that indicates the event is a request logging event.这是我尝试使用的 API,尽管我没有找到任何表明该事件是请求日志记录事件的属性。
.WriteTo.Logger(config => config
.MinimumLevel.Verbose()
.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug)
Request logs from UseSerilogRequestLogging
all have the same template, so you can use:来自
UseSerilogRequestLogging
请求日志都具有相同的模板,因此您可以使用:
.Filter.ByIncludingOnly(e => e.MessageTemplate.Text ==
"HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms")
(Assuming you're using the default template.) (假设您使用的是默认模板。)
Alternatively, since they all come from the same class:或者,因为它们都来自同一个类:
var requestLogs = Matching.FromSource("Serilog.AspNetCore.RequestLoggingMiddleware");
// ... then:
.Filter.ByIncludingOnly(requestLogs)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.