使用包装器时,如何保留类和方法名称以便 Log4Net 进行日志记录? [英] When using wrapper, how to preserve class and method name for Log4Net to log?
问题描述
我需要一个 Log4net 包装器 - 在大型应用程序中暴露给许多不同的组件.我显然想在记录时保留类和方法名称,但我会避免将类型等传递给我的包装器.
I need a Log4net wrapper - to be exposed to a number of different components in a large app. I obviously want to retain the class and method name when logging but I would keep away of passing down type etc to my wrapper.
我看了一下这个问题,这是非常相似的我的,但没有帮助.
I had a look at this question which is very similar to mine, but it didn't help.
我已经在另一个问题中看到了它smt 如下:
I've seen it done in this other question with smt like the following:
MethodBase methodBase = new StackTrace().GetFrame(1).GetMethod();
this.log.Debug(methodBase.Name + " : " + message);
这并不理想,因为它没有使用开箱即用的 Log4Net 功能.
This is not ideal since it's not using the out-of-the-box Log4Net functionality.
我想先了解一下人们是如何做这件事的,然后再去切线并想出一些非常复杂的东西.任何指针(链接/资源/示例)表示赞赏!
I'd like to get an idea of how people are doing this before I go for the tangent and come up with something very complicated. Any pointers (links/resources/samples) appreciated!
推荐答案
我通常会添加一些这样的东西...(这是我需要的所有功能)
I usually add something this... (it's all the functionality I need)
MethodBase.GetCurrentMethod().Name
你总是可以为 Log4Net 创建一个包装器来接受你需要的任何参数(比如 MethodBase)?
you could always create a wrapper for Log4Net that takes any params you need (like MethodBase)?
这篇关于使用包装器时,如何保留类和方法名称以便 Log4Net 进行日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!