2

By default only 5 first frames of the calling stack are logged by log4net when using Ilog Error(string message, Exception ex) method.

Is there a way to change it (extend it)?

PS. This is not a duplicate of "Does log4net support including the call stack in a log message". It is not about supporting including call stack in every logged message but it reffers to the amount of stack trace frames being logged when calling Error(string message, Exception ex) method.

Radek Strugalski
  • 560
  • 7
  • 22
  • https://stackoverflow.com/questions/1906227/does-log4net-support-including-the-call-stack-in-a-log-message – Derek Jun 29 '17 at 15:44
  • Possible duplicate of [Does log4net support including the call stack in a log message](https://stackoverflow.com/questions/1906227/does-log4net-support-including-the-call-stack-in-a-log-message) – Ondrej Svejdar Jun 30 '17 at 08:48
  • No, this is not related. I explicitely stated that it is about changing the default depth of stack trace being logged when **calling Error(string message, Exception ex) method**. By default it seems to be 5. I need log4net to include more of stack trace in case of logging an Exception. – Radek Strugalski Jun 30 '17 at 11:18

1 Answers1

1

You have an option to include the callstack in your log message:

stacktrace:

Used to output the stack trace of the logging event The stack trace level specifier may be enclosed between braces. For example, %stacktrace{level}. If no stack trace level specifier is given then 1 is assumed Output uses the format: type3.MethodCall3 > type2.MethodCall2 > type1.MethodCall1 This pattern is not available for Compact Framework assemblies.

This way you can include the call stack. I do not know a way of changing the number of frames in the exception. I know it is not limited to 5, it just prints exception ToString(). If you are missing a part of you exception stack, you are probably rethrowing the exception the like throw ex; instread of throw;

Peter
  • 27,590
  • 8
  • 64
  • 84