logginglog4netwrapper

When using wrapper, how to preserve class and method name for Log4Net to log?


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);

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!


Solution

  • I usually add something like this... (it's all the functionality I need)

    MethodBase.GetCurrentMethod().Name
    

    you could always create a wrapper for Log4Net that takes any params you need (like MethodBase)?