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
  • 2,131
  • 3
  • 27
  • 46

1 Answers1

12

How about:

log.ErrorFormat("My {0} message: {1}", "pretty", exception);
Joe
  • 122,218
  • 32
  • 205
  • 338
  • 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