Closed joeldickson closed 3 weeks ago
Doesn't CA2254 cover this?
just repeating internal slack thread for docs
CA2254 doesnt have a code fix and it's description in the IDE is confusing as to what is wrong
Just noting here too, claude managed to generate a test case that i didnt cover :)
i think its an obscure one, but wanted to leave it here incase we decide we want to cover it
yield return new TestCaseData(new TestCase
{
Usings = "using Microsoft.Extensions.Logging;",
SetupCode = "private readonly ILogger _logger;private string message;",
LogStatement = "_logger.LogWarning($\"Warning: {message}\" + $\" at {DateTime.Now}\");",
ExpectedFix = "_logger.LogWarning(\"Warning: {Message} at {Timestamp}\", message, DateTime.Now);",
ExpectedDiagnostics = new[]
{
new DiagnosticResult(AG0040LogTemplateAnalyzer.Rule)
.WithSpan(13, 31, 13, 78)
.WithArguments("string interpolation")
}
}).SetName("ILogger with mixed string interpolation and concatenation");
Feature request
Type
Should be able to check and warn on string interpolation or concatenation in logs and warn with a code fix to change to message template.
Also will do a fix for both serilog and ilogger as they have different signatures.
Using Message Templates vs String Interpolation in Logging
Approach Comparison
or Concatination too
Benefits of Message Templates