Hi there
Creating a new issue relating to this, as advised in the linked thread:
https://github.com/dotnet/extensions/issues/2914#issuecomment-580486450
CA1303 warnings are being generated when I am making calls to logging functions.
For example, in a method defined in one of my services it makes the following call:
this.logger.LogCritical("There is no configured setup section for the gateway {0}", site.GatewayId);
where logger is an instance ofILogger
Which triggers the warning.
Thanks
Mark
@mavasani I agree with the comment from @anurse regarding non-localized logs, as I think that it might be hard to handle all possible logging frameworks I would suggest to add support for the excluded symbols.
Looks like the rule CA1303 already supports the exclusion. I don't see much more to do.
Tagging @mavasani
I read that as switch off the rule for type X. The issue is I might write to a log and write to say can ViewBag for rendering as HTML in the same method of my type - I need to suppress it for any call to a particular function in my method
You can use this exclusion to exclude your logger which means that each call to MyLogger.LogCritical will no longer cause any issue.
I have a project in ASP .NET Core 3.1 where i added the nuget package Microsoft.CodeAnalysis.FxCopAnalyzers version 3.0.0 and the use_naming_heuristic and excluded_type_names_with_derived_types 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...");
}
}
When calling the logger with a string, I get the CA1303 warning.
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 wrong or is there possible bug here?
Yes, with this beta version it works just specifying LoggerExtensions!
Thanks for confirming! We hope to publish 3.3.0-beta1 soon on nuget.org. I'll close this issue once the package is published.
@mavasani Looks like this ticket can be closed.