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

Support use of MessageTemplateFormatMethod on extension methods #39

Closed
GitSnafu opened this issue Dec 11, 2018 · 4 comments
Closed

Support use of MessageTemplateFormatMethod on extension methods #39

GitSnafu opened this issue Dec 11, 2018 · 4 comments

Comments

@GitSnafu
Copy link

This is similar to issue #19 but concerns extension methods and the Exception argument rule and is perhaps best illustrated by an example.

public interface IMyLogger {}

public static class MyLoggerExtensions
{
    [MessageTemplateFormatMethod("messageTemplate")]
    public static void Warning(this IMyLogger logger, string messageTemplate, object arg) {}
}

Given the above, the analyzer currently fails to report on the misplaced exception in cases such as these:

IMyLogger log = null;
log.Warning("Hello World", ex);
// And
MyLoggerExtensions.Warning(log, "Hello World", ex);

Given the current implementation this makes sense as the assumption is that the Exception parameter is at position one, which obviously isn't true in the case of an extension method. I've got a repro and proposed fix that I can push for you to look at and merge if you're happy with it.

Note that the missing property in the template string is still detected and reported.

Thanks for a great analyzer, it's really indispensable once you start using Serilog extensively.

@Suchiman
Copy link
Owner

Sure, i'm happy to take a look at your fix 👍

GitSnafu pushed a commit to GitSnafu/SerilogAnalyzer that referenced this issue Dec 12, 2018
…rk for extension methods decorated with MessageTemplateFormatMethod
@GitSnafu
Copy link
Author

Great, I've submitted a PR you can take a look at. Cheers!

Suchiman pushed a commit that referenced this issue Dec 14, 2018
…xtension methods decorated with MessageTemplateFormatMethod
@Suchiman
Copy link
Owner

I've just pushed version 0.15 with your fix inside. Thanks again for the PR 👍

@GitSnafu
Copy link
Author

I've just pushed version 0.15 with your fix inside. Thanks again for the PR 👍

Thanks a lot. :)

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

2 participants