简体   繁体   English

ASP NET核心Serilog:请求,响应和异常日志的不同文件

[英]ASP NET core Serilog : Different files for Request, Response and Exception logs

I am using Serilog for logging and not able to differentiate different kinds of log in different files. 我正在使用Serilog进行日志记录,并且无法区分不同文件中的不同类型的日志。

My Requirements are:- 我的要求是:

1) Request.log (Daily Rotation)
2) Response.log (Daily Rotation)
3) Exception.log (Daily Rotation)

One method is to create a middleware for Request and Response, and Default file for Exception log. 一种方法是为请求和响应创建中间件,为异常日志创建默认文件。

Is there any other way in whcih I can do following task? 还有其他方法可以执行以下任务吗?

A more common approach is to have a single file. 一种更常见的方法是只有一个文件。

The reason is that you can correlate the log entries more easily. 原因是您可以更轻松地关联日志条目。 The way you are proposing, one request coming in that goes through your pipeline and fails (someone throws) and writes a response to the client would have related messages in 3 different files. 您提出的方式是,一个请求进入您的管道,并失败(有人抛出),并向客户端写一个响应,在3个不同的文件中有相关的消息。 That would make it harder to debug. 这将使调试变得更加困难。

You can use a request id and set it to the scope/context of that request. 您可以使用请求ID并将其设置为该请求的范围/上下文。 That way you can augment your log entries. 这样,您可以增加日志条目。 Every log entry related to that request (request/response/errors) will have the same RequestId. 与该请求相关的每个日志条目(请求/响应/错误)将具有相同的RequestId。 This way you can see what Request ended up generating that error message. 这样,您可以查看最终导致该错误消息的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM