堆栈跟踪,日志记录外观的调用点问题
日志外观(如果确实如此)如何在内部解决问题,即它们会将额外的堆栈跟踪帧添加到日志条目的上下文或模糊调用站点。似乎在某些外观(例如简单日志外观)中,调用站点将始终是外观本身。
如果我要编写自己的日志记录门面,我有哪些潜在的解决方案?
How do logging facades (if they do) solve the problem internally that they will add extra stacktrace frames to the log entry's context or obscure the callsite. It seems that in some facades (e.g. simple logging facade) the callsite will just always be the facade itself.
What potential solutions to this do I have if I were to write my own logging facade?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我对此问题的回答,了解如何为 NLog 编写包装器的一个示例:
使用包装器时,Nlog Callsite 是错误的
为了节省时间,我在这里复制了代码:
这个例子是专门针对问题的上下文编写的,它是关于包装 NLog 以与 NInject 一起使用。
转到链接以获取有关此方法为何有效以及为什么更简单的方法不起作用的更多解释。
另外,请参阅此链接以获取有关如何包装 NLog 的示例(来自 NLog 开发人员):
https://github.com/jkowalski/NLog/tree/master/examples/ExtendingLoggers
最后,考虑使用 Common.Logging for .NET 作为日志记录抽象或作为如何编写日志记录抽象的示例。
See my answer to this question for one example of how to write a wrapper for NLog:
Nlog Callsite is wrong when wrapper is used
To save time, I have copied the code here:
This example was written specifically for the context of the question, which was about wrapping NLog for use with NInject.
Go to the link to get a little bit more explanation about why this works and why more naive approaches don't work.
Also, see this link for examples (from the NLog developer) of how to wrap NLog:
https://github.com/jkowalski/NLog/tree/master/examples/ExtendingLoggers
Finally, consider using Common.Logging for .NET as a logging abstraction or as an example of how to write a logging abstraction.