Skip to content

.NET: Fix expensive logging#7268

Merged
moonbox3 merged 3 commits into
microsoft:mainfrom
alliscode:fix-logging
Jul 22, 2026
Merged

.NET: Fix expensive logging#7268
moonbox3 merged 3 commits into
microsoft:mainfrom
alliscode:fix-logging

Conversation

@alliscode

Copy link
Copy Markdown
Member

This pull request refactors how warning logs are generated when a workflow session resumes but makes no progress. The main change is moving the logging logic from an inline message to a strongly-typed logging method using source generators, which improves maintainability and consistency.

Logging improvements:

  • Replaced the inline warning log in UpdateCursor with a call to a new strongly-typed logging method, LogWorkflowResumeMadeNoProgress, in HostedWorkflowState.cs.
  • Introduced the HostedWorkflowStateLogMessages static partial class, defining the LogWorkflowResumeMadeNoProgress method using the [LoggerMessage] attribute for efficient and consistent logging.

Description & Review Guide

  • What are the major changes?
  • What is the impact of these changes?
  • What do you want reviewers to focus on?

Related Issue

Fixes #

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Avoid unnecessary structured logging argument evaluation when warning logging is disabled, resolving CA1873 in release builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0bc01e26-22ba-42ce-ac1e-6fe166500f4f
Align the no-progress warning with the repository-standard LoggerMessage source generator pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0bc01e26-22ba-42ce-ac1e-6fe166500f4f
Copilot AI review requested due to automatic review settings July 22, 2026 20:03
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 20:03 — with GitHub Actions Inactive
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 20:03 — with GitHub Actions Inactive
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 20:03 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Jul 22, 2026
@alliscode alliscode changed the title Fix logging .NET: Fix expensive logging Jul 22, 2026
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 20:04 — with GitHub Actions Inactive
@github-actions github-actions Bot changed the title .NET: Fix expensive logging .NET: Fix logging Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates .NET hosting workflow-resume diagnostics by replacing an inline LogWarning call with a source-generated, strongly-typed logging extension method, reducing per-call allocations and centralizing the message definition.

Changes:

  • Replaced the inline warning in WarnOnNoProgress with a call to a source-generated logging method.
  • Added a HostedWorkflowStateLogMessages static partial class with a [LoggerMessage]-based extension method for the “resume made no progress” warning.
Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Hosting/HostedWorkflowState.cs Switches “no progress on resume” warning to a source-generated [LoggerMessage] extension for more efficient logging.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread dotnet/src/Microsoft.Agents.AI.Hosting/HostedWorkflowState.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 20:15 — with GitHub Actions Inactive
@alliscode alliscode changed the title .NET: Fix logging .NET: Fix expensive logging Jul 22, 2026
@alliscode
alliscode temporarily deployed to github-app-auth July 22, 2026 21:09 — with GitHub Actions Inactive
@moonbox3
moonbox3 added this pull request to the merge queue Jul 22, 2026
Merged via the queue into microsoft:main with commit c68c099 Jul 22, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants