I want my logs to be in English and therefore do not want to localize them.
I have a project in ASP .NET Core 3.1 where I added the nuget package Microsoft.CodeAnalysis.FxCopAnalyzers version 3.0.0 and I am getting the warning CA1303 on all calls to _logger.LogInformation("").
I have tried to use use_naming_heuristic and excluded_type_names_with_derived_types, but they don't seem to be working with Microsoft.Extensions.Logging.LogginExtensions or Microsoft.Extensions.Logging.ILogger, so I always get the warnings.
This is my .editorconfig file:
[*.cs]
# CA1303: Do not pass literals as localized parameters
dotnet_code_quality.CA1303.use_naming_heuristic = false
dotnet_code_quality.CA1303.excluded_type_names_with_derived_types = ClassA|LoggerExtensions|ILogger
I have a class ClassA that gets an ILogger<ClassA> injected:
internal class ClassA : IClassA
{
private readonly ILogger<ClassA> _logger;
public ClassA(ILogger<ClassA> logger)
{
_logger = logger;
}
public void Initialize()
{
_logger.LogInformation("Initializing..."); // <- Always get the CA1303 in this string.
}
}
I tried with true/false, I tried also adding ILogger<> , ILogger<T> and ILogger<ClassA> but nothing makes the warning go away.
Am I misunderstanding this functionality and configuring this rule wrong or is there possible bug here?
Edit:
I added a custom class called MyLogger inheriting from IMyLogger that gets an ILogger injected. I injected the IMyLogger into the ClassA class and replace the types in excluded_type_names_with_derived_types with IMyLogger and MyLogger and the CA1303 is still there. I rebuilt and even restarted VS2019 16.5.4 but it is still there.
It's a bug already fixed in version 3.3.0-beta1.20261.6.
Source: MVC Core LogCritical etc. messages should not trigger CA1303 #3254