Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages not always formatted #116

Open
bdurrer opened this issue Oct 16, 2019 · 0 comments
Open

Messages not always formatted #116

bdurrer opened this issue Oct 16, 2019 · 0 comments

Comments

@bdurrer
Copy link

bdurrer commented Oct 16, 2019

Problem description
Passing an exception to the logger does not log the exception in all cases and the message is not always formatted.

Example

Logger.Info("formatted exception {0}.", new Exception("exception message").Message);
Logger.Info("exception {0}.", new Exception("exception message"));
Logger.Info("param and exception {0}.", "some other param", new Exception("exception message"));

Output:

12|2019-10-16 11:41:01.475|INFO|1|Test|formatted exception exception message.
13|2019-10-16 11:41:01.475|INFO|1|Test|exception {0}.>>>System.Exception: exception message<<<
14|2019-10-16 11:41:01.475|INFO|1|Test|param and exception some other param.

  1. works as expected
  2. works but fails to format
  3. fails to log the exception

Conclusion:
Only the methods with signature (string message, params object[] ps); apply formatting
Only the methods with signature (string message, Exception ex = null); log the stack trace

Expected behaviour:
NLog 4 moved the exception parameter in front of the message format string to avoid the confusion. Log4net has extra methods for logging formatted messages with an exception.

MetroLog Logger's interface has a signature close to log4j and slf4j and should behave like it:

  • The Logger should not make assumptions on wheter an exception is an formatting parameter or whether it has to be logged as an exception.
  • Both variants should check whether the last argument is an exception and pass it on as exception to the targets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant