SerilogAnalyzer
SerilogAnalyzer copied to clipboard
No Tips Showing
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?
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?
@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 the analyzer analyzes everything by the rules of serilog that is decorated with [MessageTemplateFormatMethod("messageTemplate")]
which also includes Serilogs ILogger, just not Microsofts ILogger
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 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.
Have the same issue. Doesn't highlight
Why do expressions marked "?" not highlighted?