1

Possible Duplicate:
How to log MethodName when wrapping Log4net?

I have tons of requests in log4net that show up manually as ": activity". The requests are all manually built and somewhat clumsy. Is there any way for Log4Net to pick up the source function and record that automatically?

Community
  • 1
  • 1
Steve Brians
  • 11
  • 1
  • 2

1 Answers1

2

Sure, you can use pattern layout, by specifying the %method flag you will output the calling method name, see the docs here:

http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html

e.g.

<layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d %-5p %C %method %m%n " />
      </layout>

but pay attention this can slow down the performance if you log a lot of messages ore your application is time-critical.

PUG
  • 4,301
  • 13
  • 73
  • 115
Felice Pollano
  • 32,832
  • 9
  • 75
  • 115