olsh / resharper-structured-logging

An extension for ReSharper and Rider that highlights structured logging templates and contains some useful analyzers
MIT License
141 stars 14 forks source link

Convert to compile time constant codefix should cover more cases #87

Closed MichalBrylka closed 1 year ago

MichalBrylka commented 1 year ago

Hi, The "Convert to compile time constant message template" generally works and produces nice results: image

Where it falls short is when presented with more challenging (but sadly, more frequent) structured logging bad practice i.e.:

log.InfoFormat("Name:" + name + " age " + age);

No code fix is presented in such case: image

While it might be tempting to add support for such bad-practices fixes, I'd propose to alternatively allow R# to use it's own "Convert concatenation to interpolation" action: image

Your plugin somehow prohibits this action from displaying in suggestion list

Would it be feasible to allow R# to propose it's own suggestions/code fixes ?

Using "Convert concatenation to interpolation" followed by your code fix would allow many ill-structured logging calls to be mended

olsh commented 1 year ago

Hi @MichalBrylka

Your plugin somehow prohibits this action from displaying in suggestion list

The plugin doesn't prohibit any fixes explicitly. I get the same results whether the plugin is installed or not.

            var s = new Random().Next();

            // There is a fix for this
            var hello = "Hello" + s + "World";

            // There is no fix for this
            _logger.LogInformation("Hello" + s + "World");
olsh commented 1 year ago

Closed due to inactivity