.NET: fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour…#6814
Merged
alliscode merged 1 commit intoJun 30, 2026
Merged
Conversation
…ce generator Replace the direct logger.LogWarning() call (which eagerly evaluates string.Join()) with a [LoggerMessage]-generated extension method in GitHubCopilotAgentLogMessages.cs. Fixes build error: GitHubCopilotAgent.cs(580,13): error CA1873: Evaluation of this argument may be expensive and unnecessary if logging is disabled Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors a warning log in the .NET GitHub Copilot agent to use source-generated LoggerMessageAttribute logging, addressing CA1873 and aligning the log site with the repository’s existing strongly-typed logging patterns.
Changes:
- Added a
GitHubCopilotAgentLogMessagesextension class with aLoggerMessageAttribute-based warning log method. - Updated
GitHubCopilotAgentto call the new strongly-typed log method instead oflogger.LogWarning(...).
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgentLogMessages.cs | Introduces the source-generated logging extension for the approval-gating warning. |
| dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs | Switches the warning log call site to use the new generated logging method. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
TaoChenOSU
approved these changes
Jun 30, 2026
chetantoshniwal
approved these changes
Jun 30, 2026
This was referenced Jul 2, 2026
Open
Open
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how warnings are logged when a custom
OnPreToolUsehook is present in theSessionConfig. Instead of using a rawlogger.LogWarningcall, it introduces a strongly-typed logging extension usingLoggerMessageAttributefor improved performance and maintainability.Logging improvements:
GitHubCopilotAgentLogMessages.csthat defines aLogApprovalGatingSkippedDueToCustomHookextension method usingLoggerMessageAttributefor compile-time optimized logging.GitHubCopilotAgent.csto use the newLogApprovalGatingSkippedDueToCustomHookmethod instead of a directLogWarningcall.