A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Suchiman/SerilogAnalyzer/issues/39 below:

Support use of MessageTemplateFormatMethod on extension methods · Issue #39 · Suchiman/SerilogAnalyzer · GitHub

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4