Skip to content

Messages not always formatted #116

@bdurrer

Description

@bdurrer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions