使用包装器时,如何保留类和方法名称以供Log4Net记录? [英] When using wrapper, how to preserve class and method name for Log4Net to log?

查看:61
本文介绍了使用包装器时,如何保留类和方法名称以供Log4Net记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个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.

我在其他问题中看到了这一点如下所示:

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屋!

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