3

Using the preferred form of

_log.Error("Message", exception)

does not log my stack trace. To get around this I have to make sure the .ToString() gets call on the exception by doing the following.

_log.Error("Message" + exception);

But I know that's wrong, only I can't make the correct version work. Do I need a special line in my log4net.xml file to make this work?

Jonathan Beerhalter
  • 7,229
  • 16
  • 68
  • 78
  • 1
    There is a "StackTrace" in your exception? Put another way: Your exception was thrown, or was simply created and passed to the method "Error"? In the second case (created but not thrown) there will be no Stacktrace. – Hailton Jul 17 '12 at 21:29
  • Thrown, I tested it by calling throw new Exception("Please give me a trace") – Jonathan Beerhalter Jul 17 '12 at 21:36
  • 1
    Did you try to use "exception" "Conversion Pattern Name"? So your "ConversionPattern" should be like this "%d{ABSOLUTE} %-5p %c{1}:%L - %m%n%exception" – Hailton Jul 17 '12 at 22:33
  • Now log4net won't log anything. Not regular INFO messages nor exceptions. I'm starting to think my solution is the best way to go – Jonathan Beerhalter Jul 18 '12 at 14:58

1 Answers1

2

I wanted to provide my eventual answer, just for reference. I had implemented an asynchronous appender scheme for log4net using my answer to the SO question How do I create an asynchronous wrapper for log4net?

I noted in my response that you need to be careful about the FixFlags, because anything not in the FixFlags will get dropped from the original logging event. Unfortunately, I did not add FixFlags.Exception to my original solution, so any exceptions generated get dropped during the forwarding process.

Changing my FixFlags from

loggingEvent.Fix = FixFlags.ThreadName;

To

loggingEvent.Fix = FixFlags.ThreadName | FixFlags.Exception;

Fixed the issue.

Community
  • 1
  • 1
Jonathan Beerhalter
  • 7,229
  • 16
  • 68
  • 78