.NET: fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour…#6815
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>
chetantoshniwal
approved these changes
Jun 30, 2026
TaoChenOSU
approved these changes
Jun 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens warning logging in the .NET GitHub Copilot agent so that the “approval gating skipped due to custom hook” warning is only emitted when warning-level logging is enabled, avoiding unnecessary work when warnings are filtered out.
Changes:
- Added a
logger.IsEnabled(LogLevel.Warning)guard around the approval-gating warning log call. - Ensures the
string.Join(...)for tool names is only computed when warning logs will be emitted.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs | Guards a warning log emission to avoid unnecessary allocations/work when warning logging is disabled. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Low
Comment on lines
576
to
+581
| // A caller-supplied OnPreToolUse hook takes precedence and is fully responsible for approval handling. | ||
| // Warn so the developer knows the ApprovalRequiredAIFunction marker(s) will not be automatically gated. | ||
| if (sessionConfig.Hooks?.OnPreToolUse is not null) | ||
| { | ||
| logger.LogApprovalGatingSkippedDueToCustomHook( | ||
| approvalRequiredToolNames.Count, | ||
| string.Join(", ", approvalRequiredToolNames)); | ||
| if (logger.IsEnabled(LogLevel.Warning)) | ||
| { |
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 makes a minor update to the
ConvertToAgentResponseUpdatemethod inGitHubCopilotAgent.cs. The change ensures that warning logs about approval gating being skipped due to a custom hook are only emitted if the logger is configured to show warnings, preventing unnecessary log output.logger.IsEnabled(LogLevel.Warning)before logging a warning when a customOnPreToolUsehook is present, ensuring that warnings are only logged if enabled.