Skip to content

CA1873 potential false positive for non-expensive logging parameters #51903

@joshuahills

Description

@joshuahills

Describe the bug

The CA1873 analyzer enabled by default in .NET 10 is flagging the log call in the below minimal repro for a logging parameter that is not expensive. The examples in the docs make sense, however this does not. Is this intended behaviour and all log messages should now be wrapped in an if (logger.IsEnabled(...)) block?

To Reproduce

Minimal repro: https://github.com/joshuahills/ca1873-false-positive

  1. Clone repo
  2. Build solution
  3. Observe build error

Exceptions (if any)

n/a

Further technical details

details of dotnet --info

.NET SDK: Version: 10.0.100 Commit: b0f34d51fc Workload version: 10.0.100-manifests.5fb86115 MSBuild version: 18.0.2+b0f34d51f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\

Microsoft Visual Studio Professional
Channel: Insiders
Version: Insiders [11218.70]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions