Skip to content

Route production channel logs to MSBuild - #17406

Merged
akoeplinger merged 1 commit into
mainfrom
fix-production-channel-logging
Aug 26, 2026
Merged

akoeplinger merged 1 commit into
mainfrom
fix-production-channel-logging

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

Production channel validation services used ILoggerFactory without an MSBuild logging provider, so informational messages were discarded even though task warnings still appeared in binlogs.

Inject typed MSBuildLogger adapters directly so validator and HTTP service logs flow through TaskLoggingHelper and are captured by MSBuild.

Co-authored-by: Copilot [email protected]

To double check:

@akoeplinger
akoeplinger requested review from mmitche and a lite review from Copilot August 25, 2026 14:15

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 ensures production-channel validation diagnostics are emitted through MSBuild logging so they appear in binlogs/output, by replacing ILoggerFactory-based logging (without a provider) with direct TaskLoggingHelper-backed logger adapters.

Changes:

  • Inject MSBuildLogger<T> adapters directly into ProductionChannelValidator, AzureDevOpsService, and BranchClassificationService registrations.
  • Add a typed MSBuildLogger<T> implementation to satisfy ILogger<T> consumers.
  • Add a unit test asserting validator informational logs flow into the MSBuild build engine message events.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs Switches DI factories to construct typed MSBuild loggers instead of using ILoggerFactory/AddLogging.
src/Microsoft.DotNet.Build.Tasks.Feed/src/MSBuildLogger.cs Adds a typed MSBuildLogger<T> adapter implementing ILogger<T>.
src/Microsoft.DotNet.Build.Tasks.Feed.Tests/PublishArtifactsInManifestTests.cs Adds a test verifying validator informational logs are captured as MSBuild messages.
Suppressed comments (2)

src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs:258

  • Same as above: resolve TaskLoggingHelper from the service provider rather than capturing the outer task's Log property, so logging dependencies come from DI and the lambda doesn't close over the task instance.
            {
                var httpClient = provider.GetRequiredService<HttpClient>();
                var logger = new MSBuildLogger<AzureDevOpsService>(Log);
                return new AzureDevOpsService(httpClient, logger, AzdoApiToken);

src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs:266

  • Same as above: resolve TaskLoggingHelper from the service provider rather than capturing the outer task's Log property, so logging dependencies come from DI and the lambda doesn't close over the task instance.
            {
                var httpClient = provider.GetRequiredService<HttpClient>();
                var logger = new MSBuildLogger<BranchClassificationService>(Log);
                return new BranchClassificationService(httpClient, logger, AzdoApiToken);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 25, 2026 15:31

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Build.Tasks.Feed.Tests/PublishArtifactsInManifestTests.cs:289

  • Use Array.Empty() instead of allocating a new zero-length array in tests.
                targetFeeds: new TargetFeedSpecification[0],

Copilot AI review requested due to automatic review settings August 25, 2026 15:34
Production channel validation services used ILoggerFactory without an MSBuild logging provider, so informational messages were discarded even though task warnings still appeared in binlogs.

Inject typed MSBuildLogger adapters backed by the DI-registered TaskLoggingHelper so validator and HTTP service logs are captured by MSBuild.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 21d1a33e-601f-4ef8-8c28-208a614a1158
@akoeplinger
akoeplinger force-pushed the fix-production-channel-logging branch from 0686720 to e8f9fc0 Compare August 25, 2026 15:35

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (4)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs:247

  • ConfigureServices manually new's up MSBuildLogger instances instead of letting DI resolve ILogger. Registering MSBuildLogger<> as the open-generic ILogger<> implementation reduces duplication and ensures any future services that request ILogger automatically route logs through MSBuild.

This issue also appears on line 255 of the same file.

            collection.TryAddSingleton<ITargetChannelValidator>(provider =>
            {
                var buildInfoService = provider.GetRequiredService<IProductionChannelValidatorBuildInfoService>();
                var branchClassificationService = provider.GetRequiredService<IBranchClassificationService>();
                var logger = new MSBuildLogger<ProductionChannelValidator>(provider.GetRequiredService<TaskLoggingHelper>());
                

src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs:267

  • Once MSBuildLogger<> is registered as the ILogger<> implementation, the service factories can resolve ILogger from DI rather than constructing MSBuildLogger directly. This keeps logger creation consistent and avoids repeating TaskLoggingHelper plumbing in each factory.
            collection.TryAddSingleton<IProductionChannelValidatorBuildInfoService>(provider =>
            {
                var httpClient = provider.GetRequiredService<HttpClient>();
                var logger = new MSBuildLogger<AzureDevOpsService>(provider.GetRequiredService<TaskLoggingHelper>());
                return new AzureDevOpsService(httpClient, logger, AzdoApiToken);
            });
            
            // Register BranchClassificationService with proper authentication
            collection.TryAddSingleton<IBranchClassificationService>(provider =>
            {
                var httpClient = provider.GetRequiredService<HttpClient>();
                var logger = new MSBuildLogger<BranchClassificationService>(provider.GetRequiredService<TaskLoggingHelper>());
                return new BranchClassificationService(httpClient, logger, AzdoApiToken);

src/Microsoft.DotNet.Build.Tasks.Feed/src/MSBuildLogger.cs:57

  • MSBuildLogger is newly introduced as a public type but is only used as an internal adapter for DI/typed logging within the tasks assembly. Making it non-public avoids expanding the assembly's public API surface unnecessarily.
    public class MSBuildLogger<T> : MSBuildLogger, ILogger<T>

src/Microsoft.DotNet.Build.Tasks.Feed.Tests/PublishArtifactsInManifestTests.cs:299

  • This test currently asserts MessageImportance.High, which hard-codes the MSBuildLogger LogLevel->importance mapping and makes the test brittle (and implicitly encourages high-importance informational logs). It’s enough to assert the message flowed through the MSBuild build engine.
            buildEngine.BuildMessageEvents.Should().Contain(message =>
                message.Importance == Microsoft.Build.Framework.MessageImportance.High &&
                message.Message == "Validating build 12345 for production channel 1");
        }

Copilot AI review requested due to automatic review settings August 25, 2026 15:40

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@akoeplinger

Copy link
Copy Markdown
Member Author

@mmitche I noticed that the promotion pipeline logged a warning about "Build validation audit failure for production channel 8298. This is currently treated as a warning" but there were no details about the underlying reason in the binlog. This fixes that.

@akoeplinger
akoeplinger merged commit d2da45c into main Aug 26, 2026
12 of 13 checks passed
@akoeplinger
akoeplinger deleted the fix-production-channel-logging branch August 26, 2026 16:16
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants