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

Passing exception into Logger as message arg #168

Open
1 of 2 tasks
szaboopeeter opened this issue Aug 9, 2022 · 1 comment
Open
1 of 2 tasks

Passing exception into Logger as message arg #168

szaboopeeter opened this issue Aug 9, 2022 · 1 comment

Comments

@szaboopeeter
Copy link
Member

Feature request

Type

  • - Enhancement - completely new feature
  • - Improvement - make what we have better

Is your feature request related to a problem?

Microsoft.Extensions.Logging.LoggerExtensions have several overloads that take exceptions. The signature is usually in the format of

public static void LogInformation(this ILogger logger, Exception exception, string message, params object[] args)

the exception being the first parameter of the extension method.

There is another overload, that doesn't take an exception:

public static void LogInformation(this ILogger logger, string message, params object[] args)

People often make a mistake of using this overload, assuming that the exception is the second parameter, like

_logger.LogError("Something went wrong", ex);

This will result in logs that doesn't contain any information about the actual exception, since it will just try to fit ex into the message template.

Describe the solution you'd like

Show warning if an exception is passed as a parameter to an overload that does not take an exception as a parameter. Even if the intent is to pass the exception into the message template, I believe we should use the overload that also takes the message.

Additional context

N/A

@dicko2
Copy link
Contributor

dicko2 commented Aug 9, 2022

Sounds like a good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants