November Happy Hour will be moved to Thursday December 5th.

LoggerExtensions.Error("message", exception) duplicates exception in output

Vote:
 
ILogger log = GetLoggerFromSomeWhere();

log.Error("Message", exception)

Consider the code above.

In the output to the underlying log framework, the exception.ToString() (containing Exception message + stacktrace) is appended to your own message, which IMO is unintuitive, unexpected and completely unnecessary behaviour. I know I can override this with my own messageformatter-Func, but that's unnecessary clutter scattered in my own code just because of the default value.

When decompiling, it seems that it defaults to LoggerExtensions.StateAndExceptionMessageFormatter , where I think it should default to LoggerExtensions.StringMessageFormatter.

I don't know if this is intentional, or should be considered a bug. To me, since logging frameworks (and log4net is the default one anyways) generally know about the concept exceptions, it should be unnecessary to manually append the exception.ToString() since that's included in a separate field. Or, if it should really be general enough to let everything end up in one string in the end, at least let me configure the defaults somehow, so I don't need to clutter my code with a messageFormatter every time I call .Error with an exception.

#162417
Oct 14, 2016 10:23
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.