log4net - 创建许多记录器用于跟踪目的是一个好习惯吗?
我想向我的消息应用程序添加跟踪功能。我使用的每条消息都有一个唯一的标识符,该标识符将延续到后续消息(由原始消息生成的消息)。
为了能够跨多个进程和潜在的服务器监视消息的生命周期行为,我想使用 log4net 远程附加程序。
我可以使用一个记录器并在消息本身中对消息 ID 进行编码:
Logger: "MessageLivetime"
Message: "SomeId | message text")
不过我认为这会很聪明如果我为每条消息创建一个记录器:
Logger: "MessageLivetime.SomeId"
Message: "message text")
但是,由于 LogManager
类没有删除记录器的方法 我担心会遇到问题,因为将会创建数千个废弃的记录器。
对 log4net 有更深入了解的人可以给我提示这种方法是否可行吗?
我已经找到了上下文属性。他们是更好的选择吗?如何写入事件上下文?
I want to add tracing capabilities to my messaging application. Each message I use has an unique identifier which is carried on to subsequent messages (messages spawned by the original message).
To be able to monitor the lifetime behavior of a message across multiple processes and potentially servers I want to use the log4net remoting appender.
I could use one logger and encode the message ID in the message itself:
Logger: "MessageLivetime"
Message: "SomeId | message text")
However I thought it would be smart if I created a logger per message:
Logger: "MessageLivetime.SomeId"
Message: "message text")
However since the LogManager
class hast no method to remove a logger I worry about running into problems because thousands of abandoned loggers will be created.
Can someone with more insight to log4net give me a hint if this approach is viable?
I already found context properties. Are they be a better option? And how do I write to the event context?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为将 ID 包含在记录器本身中没有任何好处。对我来说,这感觉是错误的。
本教程有关日志记录上下文可能会有所帮助你。假设单个消息的所有内容都发生在单个线程中,您可以为消息 ID 设置上下文属性,使用适当的日志记录格式,并且消息 ID 将仅显示在日志中。
I don't see any benefit in including the ID within the logger itself. It feels the wrong way round to me.
This tutorial on logging contexts may help you. Assuming everything for a single message occurs in a single thread, you can set a context property for the message ID, use an appropriate logging format, and the message ID will just appear in the logs for you.