8

I would like to use ErrorFormat method because it is easer to read, safer and faster. But I also want to log the exception stacktrace.

I tried log.ErrorFormat("My {0} message", "pretty", exception);

But it only logs "My pretty message" Is it possible to use Error/Debug/Info Format in such way?

Thanks.

Fernando
  • 1,993
  • 3
  • 25
  • 45

1 Answers1

12

How about:

log.ErrorFormat("My {0} message: {1}", "pretty", exception);
Joe
  • 118,426
  • 28
  • 194
  • 329
  • 1
    Although it's worth noting that this formats the exception into the log message, so for example if you use Log4Net's PatternLayout's `stackTrace` or `exception` placeholders they won't contain anything. – Rory Apr 20 '16 at 21:57