Skip to content

.NET: Fixed CA1873 warning#4479

Merged
dmytrostruk merged 1 commit intomicrosoft:mainfrom
dmytrostruk:dotnet-logging-fix
Mar 4, 2026
Merged

.NET: Fixed CA1873 warning#4479
dmytrostruk merged 1 commit intomicrosoft:mainfrom
dmytrostruk:dotnet-logging-fix

Conversation

@dmytrostruk
Copy link
Member

Motivation and Context

Fixes CA1873 warning:

##[error]dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs(752,166): Error CA1873: Evaluation of this argument may be expensive and unnecessary if logging is disabled

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@dmytrostruk dmytrostruk self-assigned this Mar 4, 2026
Copilot AI review requested due to automatic review settings March 4, 2026 20:23
@dmytrostruk dmytrostruk enabled auto-merge March 4, 2026 20:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a .NET analyzer failure (CA1873) by avoiding potentially expensive log-argument evaluation when warning logging is disabled in ChatClientAgent.

Changes:

  • Guard the chat history provider conflict warning log with ILogger.IsEnabled(LogLevel.Warning).
  • Precompute GetLoggingAgentName() only when the warning will actually be emitted.

@dmytrostruk dmytrostruk added this pull request to the merge queue Mar 4, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 4, 2026
@dmytrostruk dmytrostruk merged commit fd981da into microsoft:main Mar 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants