4

I'm using Log4Net to log a multilayer-ed Enterprise Application.

I know that when I log an exception with Log4Net, it automatically exposes the exception StackTrace, but I want to log the StackTrace for every log call, even if those are not exception throws.

Why do I need that?... I want to know the call origin of the log (drilldown the layers...)

Thank all...

Tiago Dias

Ralph Willgoss
  • 11,750
  • 4
  • 64
  • 67
TiagoDias
  • 1,785
  • 1
  • 16
  • 21

2 Answers2

3

I came to a solution to my problem. I've wrap around the log4net in my own methods and i've created LoggingEvent intances. In each instance i've used a property with Environment.StackTrace.

This way i have StackTrace foreach log event in my application, even without exceptions being throwned.

Thank U all..

TiagoDias
  • 1,785
  • 1
  • 16
  • 21
1

You can get the caller method name and line number using %location, but not the entire stack trace without extending log4net. Check responses to this question:

Does log4net support including the call stack in a log message

Also check the PatternLayout documentation page on apache.org for other location details you can output:

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

Not sure if this still applies on modern computers, but the log4net documentation warns that generating caller information is costly.

Community
  • 1
  • 1
EventHorizon
  • 2,916
  • 22
  • 30