开发者

log4net - is it a good practice create many loggers for tracing purposes?

开发者 https://www.devze.com 2023-02-25 00:29 出处:网络
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开发者_StackOverflow社区 by the

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开发者_StackOverflow社区 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号