Skip to content

.NET: Use source-generated logging in Foundry Hosting - #10122

Merged
Roger Barreto (rogerbarreto) merged 3 commits into
mainfrom
foundry-source-generated-logging
Nov 5, 2026
Merged

Roger Barreto (rogerbarreto) merged 3 commits into
mainfrom
foundry-source-generated-logging

Conversation

@rogerbarreto

@rogerbarreto Roger Barreto (rogerbarreto) commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

The Foundry Hosting package still used direct ILogger.Log* extension calls while the rest of the repository favors compile-time generated logging. Migrating these calls removes repeated runtime template processing and aligns the package with the established logging pattern without changing emitted log behavior.

Description & Review Guide

  • What are the major changes? Migrated all 29 direct logging calls in Microsoft.Agents.AI.Foundry.Hosting to private [LoggerMessage] methods at the end of six partial owning types, matching the repository's dominant pattern for component-local generated logging. Removed manual IsEnabled checks where generated methods provide the same guard. Enhanced the recording logger and existing component tests to assert levels, event metadata, templates, structured properties, and exception association.
  • What is the impact of these changes? There is no public API change. Levels, numeric event IDs, message templates, punctuation, structured property names and values, exception association, and emission conditions are preserved. Every migrated message explicitly retains the legacy numeric EventId value of 0. The source generator always assigns the generated method name to EventId.Name, including when EventName is explicitly null or empty, so the name changes from null to the generated method name; tests capture both fields and this metadata difference is intentional for the source-generation migration. No OAuth consent URL, isolation value, credential, or token is added to logging. Validation passed:
    • dotnet build src\Microsoft.Agents.AI.Foundry.Hosting\Microsoft.Agents.AI.Foundry.Hosting.csproj -c Debug --tl:off --warnaserror --no-restore — passed for net8.0, net9.0, and net10.0 with 0 warnings and 0 errors.
    • dotnet build tests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests.csproj -c Debug --tl:off --warnaserror --no-restore — passed for net8.0, net9.0, and net10.0 with 0 warnings and 0 errors.
    • dotnet test --project tests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests.csproj -f net10.0 -c Debug --no-build — passed: 644 succeeded, 0 failed, 1 pre-existing skipped test.
    • dotnet format src\Microsoft.Agents.AI.Foundry.Hosting\Microsoft.Agents.AI.Foundry.Hosting.csproj --verify-no-changes --verbosity diagnostic — passed natively on Windows with 0 files changed.
    • dotnet format tests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests\Microsoft.Agents.AI.Foundry.Hosting.UnitTests.csproj --verify-no-changes --verbosity diagnostic — passed natively on Windows with 0 files changed.
    • The CI Docker formatting command could not be run because the Docker Desktop Linux engine was unavailable; the equivalent repository-scoped native commands above passed.
  • What do you want reviewers to focus on? Verify the one-to-one parity between each former direct call and its generated method, especially numeric EventId = 0, template/property casing, exception placement, and privacy-sensitive toolbox paths. The generated methods are intentionally colocated with their single owning component and do not use #region, matching nearby repository examples.

Related Issue

N/A - trivial change. This is a mechanical internal logging refactor with no public behavior change, and no competing open pull request was found.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Copilot assisted with the logging migration, focused tests, convention review, EventId compatibility fix, validation, and this pull request description.

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 links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • 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 the title prefix in sync automatically.

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.

🟡 Changes recommended

The six new logging classes change legacy EventId metadata, potentially affecting filtering and grouping; preserve it or document the intentional change and assert numeric IDs and names in parity tests.

1 open issue
What changed in this PR

Migrates Foundry Hosting’s .NET logging to source-generated methods, reducing runtime logging overhead and aligning with the repository’s established pattern.

Changes:

  • Replaces 29 direct logging calls with six component-local logging classes.
  • Removes manual level checks where generated methods provide guards.
  • Extends the recording logger and adds focused tests for messages, levels, structured properties, and exceptions.
File Description
dotnet/​tests/​Microsoft.Agents.AI.Foundry.Hosting.UnitTests/​SourceGeneratedLoggingTests.cs Adds focused logging-parity tests.
dotnet/​tests/​Microsoft.Agents.AI.Foundry.Hosting.UnitTests/​RecordingLoggerFactory.cs Captures structured log properties.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​HostedStoredOutputHealthCheckLogMessages.cs Defines generated health-check logs.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​HostedStoredOutputHealthCheck.cs Migrates health-check logging calls.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​HostedProtocolCompatibilityFilterLogMessages.cs Defines the generated protocol-rejection log.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​HostedProtocolCompatibilityFilter.cs Migrates protocol-rejection logging.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryToolboxServiceLogMessages.cs Defines generated toolbox logs.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryToolboxService.cs Migrates toolbox lifecycle and approval logging.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryJsonCheckpointStoreLogMessages.cs Defines generated checkpoint-store logs.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryJsonCheckpointStore.cs Migrates checkpoint retry and pruning logging.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryAgentSessionStoreLogMessages.cs Defines the generated missing-session log.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​FoundryAgentSessionStore.cs Migrates session-deletion logging.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​AgentFrameworkResponseHandlerLogMessages.cs Defines generated response-handler logs.
dotnet/​src/​Microsoft.Agents.AI.Foundry.Hosting/​AgentFrameworkResponseHandler.cs Migrates response execution and resolution logging.

Review effort: Balanced

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): 7bf5699c2a23
Model: gpt-5.6-sol

Overview

The PR consistently migrates 29 Foundry Hosting log calls into component-local source-generated declarations, and focused tests preserve levels, templates, structured fields, and exception association. Existing enabled-level guards and privacy-sensitive arguments remain intact. However, the generated declarations do not preserve the prior event identity, which can break consumers that filter or query these logs by EventId.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/AgentFrameworkResponseHandlerLogMessages.cs

@github-code-quality

github-code-quality Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 3af8584 foundry-source-gener... c01e0ee +/-
86% 86% 0%
View coverage of the 5 most impacted files.
File main 3af8584 foundry-source-gener... c01e0ee +/-
/home/runner/wo...SessionStore.cs 100% 56% -44%
/home/runner/wo...olboxService.cs 98% 98% 0%
/home/runner/wo...bilityFilter.cs 100% 100% 0%
/home/runner/wo...ponseHandler.cs 89% 95% +6%
/home/runner/wo...gerMessage.g.cs 0% 93% +93%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 05, 2026 18:24 UTC

Source generation always assigns the method name as EventId.Name, but explicit EventId=0 preserves the numeric identity used by the direct Log* calls. Tests capture both fields to document the remaining name change.
@rogerbarreto
Roger Barreto (rogerbarreto) added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 4be280d Nov 5, 2026
49 of 52 checks passed
@rogerbarreto
Roger Barreto (rogerbarreto) deleted the foundry-source-generated-logging branch November 5, 2026 21:34

This branch was previously deployed

2 inactive deployments
github-app-auth — c01e0eed Deployed Nov 5, 2026 by rogerbarreto via add_label #27193
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.

3 participants