Repository navigation
Route production channel logs to MSBuild - #17406
Conversation
There was a problem hiding this comment.
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 intoProductionChannelValidator,AzureDevOpsService, andBranchClassificationServiceregistrations. - Add a typed
MSBuildLogger<T>implementation to satisfyILogger<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
TaskLoggingHelperfrom the service provider rather than capturing the outer task'sLogproperty, 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
TaskLoggingHelperfrom the service provider rather than capturing the outer task'sLogproperty, 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.
There was a problem hiding this comment.
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],
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
0686720 to
e8f9fc0
Compare
There was a problem hiding this comment.
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");
}
|
@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. |
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: