【问题标题】:Disable / Turn off FxCop CA1303 when calling LoggerExtensions methods in ASP .NET Core 3.1在 ASP .NET Core 3.1 中调用 LoggerExtensions 方法时禁用/关闭 FxCop CA1303
【发布时间】:2020-05-12 10:38:41
【问题描述】:

我希望我的日志是英文的,因此不想本地化它们。

我在 ASP .NET Core 3.1 中有一个项目,我在其中添加了 nuget 包 Microsoft.CodeAnalysis.FxCopAnalyzers 版本 3.0.0,并且在所有对 _logger.LogInformation("") 的调用中都收到警告 CA1303。

我曾尝试使用 use_naming_heuristicexcluded_type_names_with_derived_types,但它们似乎不适用于 Microsoft.Extensions.Logging.LogginExtensionsMicrosoft.Extensions.Logging.ILogger,所以我总是收到警告。

这是我的 .editorconfig 文件:

[*.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

我有一个类 ClassA 注入了 ILogger<ClassA>

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.
    }
}

我尝试使用 true/false,还尝试添加 ILogger&lt;&gt;ILogger&lt;T&gt;ILogger&lt;ClassA&gt;,但没有任何东西可以让警告消失。

我是否误解了这个功能并错误地配置了这个规则,或者这里可能存在错误?

编辑:

我添加了一个名为MyLogger 的自定义类,该类继承自IMyLogger,它注入了ILogger。我将IMyLogger 注入到ClassA 类中,并将excluded_type_names_with_derived_types 中的类型替换为IMyLoggerMyLogger,CA1303 仍然存在。我重建甚至重新启动了 VS2019 16.5.4 但它仍然存在。

【问题讨论】:

    标签: c# fxcop asp.net-core-3.1


    【解决方案1】:

    【讨论】:

    • 我不允许使用测试版。有什么替代解决方案?
    猜你喜欢
    • 2020-04-03
    • 2020-09-09
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多