是否有与 log4net 的 BufferingForwardingAppender 等效的 SeriLog 仅用于详细记录警告/错误? [英] Is there a SeriLog equivalent of log4net's BufferingForwardingAppender for detailed logging only on warning/error?

查看:49
本文介绍了是否有与 log4net 的 BufferingForwardingAppender 等效的 SeriLog 仅用于详细记录警告/错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Serilog 中是否有一种方法可以设置一个(有限大小的)日志缓冲区来收集指定级别及更高级别(即 DEBUG)的所有日志事件,但不会将它们记录到目标接收器中除非某个更高级别的事件发生(即WARNING)?

Is there a way in Serilog to setup a (limited size) log-buffer that collects all log events of a specified level and above (i.e. DEBUG) but does not log them into the target sink unless a certain higher level event happens (i.e. WARNING)?

基本上我是在问是否有办法从 log4net 复制 BufferingForwardingAppender 功能.

Basically I'm asking if there is a way to replicate the BufferingForwardingAppender functionality from log4net.

推荐答案

Serilog 在撰写本文时没有与 Log4Net 的 BufferingForwardingAppender 等效的开箱即用工具,但有一些社区构建的可能有用的接收器:

Serilog doesn't have an equivalent of Log4Net's BufferingForwardingAppender out-of-the-box as of this writing, but there are some sinks built by the community that might be useful:

或者,创建自己的 Sink 应该很容易实现该行为.

Alternatively it should be easy to create your own Sink to implement that behavior.

在这种情况下,您可能需要查看 Serilog.Sinks.Async 寻求灵感,因为它向您展示了一种将多个接收器包装成一个的方法,这将使您有机会在转发到接收器之前缓冲日志消息.

In that case you might want to look at the code of Serilog.Sinks.Async for inspiration, as it shows you a way of wrapping multiple sinks into one which would give you the opportunity for buffering the log messages before forwarding to the sinks.

最后,因为你熟悉Log4Net,所以你可以通过Log4Net Serilog Sink.

Finally, because you're familiar with Log4Net, you can integrate Log4Net with Serilog and use Log4Net's BufferingForwardingAppender by using the Log4Net Serilog Sink.

这篇关于是否有与 log4net 的 BufferingForwardingAppender 等效的 SeriLog 仅用于详细记录警告/错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆