SerilogAnalyzer icon indicating copy to clipboard operation
SerilogAnalyzer copied to clipboard

No Tips Showing

Open DavidRogersDev opened this issue 6 years ago • 6 comments

Hi. I just created a console project to test out this analyzer. I cannot seeing anything in the way of tooltips etc.

I have used Serilog 2.5.0 and SerilogAnalyzer 0.13.0.0, both .net 4.6.2 in a full framework (not .NET Core) project.

Is there a dependency I need to install which I am missing?

DavidRogersDev avatar Mar 28 '18 22:03 DavidRogersDev

Assuming you've installed everything correctly, do you have a code sample where you'd expect something to happen and what would you expect to see in particular? How did you install it? Visual Studio Extension or the nuget analyzer?

Suchiman avatar Mar 28 '18 22:03 Suchiman

@DavidRogersDev They will only show if you are using the static Log logger, not the ILogger from Microsoft.Extensions.Logging. This threw me for a while until I realised why I wasn't seeing any tooltips. It does mean the analyzer hasn't really helped us, as we use the ILogger in nearly all logging situations.

markashton avatar Aug 06 '18 13:08 markashton

@markashton the analyzer analyzes everything by the rules of serilog that is decorated with [MessageTemplateFormatMethod("messageTemplate")] which also includes Serilogs ILogger, just not Microsofts ILogger

Suchiman avatar Aug 06 '18 14:08 Suchiman

I'm not sure I completely follow - there is an open issue asking for support for Microsoft.Extensions.Logging.ILogger (https://github.com/Suchiman/SerilogAnalyzer/issues/15) and if I purposefully write a 'bad' log line such as this: _logger.LogInformation("No result found for query, SearchTerm{searchTerm} Page:{page} PerPage:{perPage}", searchTerm); ... then the analyzer will not highlight any problems. If I change that line to use the static Serilog logger like so: Log.Information("No result found for query, SearchTerm{searchTerm} Page:{page} PerPage:{perPage}", searchTerm); ... then the analyzer correctly complains about the casing of my properties, and the missing arguments.

In this case my _logger is an Microsoft.Extensions.Logging.ILogger<SearchController>

markashton avatar Aug 06 '18 14:08 markashton

@markashton if you use

Serilog.ILogger _logger = Log.ForContext<T>();
_logger.Information("No result found for query, SearchTerm{searchTerm} Page:{page} PerPage:{perPage}", searchTerm);

then it also works. Authors of logging Frameworks are not very creative 😉 so the interface is usually ILog or ILogger, both, Microsoft and Serilog, have an ILogger interface, SerilogAnalyzer also works on Serilog.ILogger because it's decorated with [MessageTemplateFormatMethod("messageTemplate")] which is the indicator for the analyzer that this method should be analyzed. SerilogAnalyzer doesn't care about static classes or specific classes, it only cares about methods decorated with that attribute.

Suchiman avatar Aug 06 '18 16:08 Suchiman

Have the same issue. Doesn't highlight image

Why do expressions marked "?" not highlighted?

image

Alexandr-Pletnev avatar Dec 13 '22 13:12 Alexandr-Pletnev