-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report workspace messages for warnings/errors from the build hosts
This connects our various error reporting systems so failures of the build hosts can get passed along back to the existing reporting mechanism for MSBuildWorkspace failures.
- Loading branch information
1 parent
27e5f16
commit 56b4868
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporterLoggerProvider.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Diagnostics.Contracts; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.CodeAnalysis.MSBuild; | ||
|
||
internal class DiagnosticReporterLoggerProvider : ILoggerProvider | ||
{ | ||
private readonly DiagnosticReporter _reporter; | ||
|
||
public DiagnosticReporterLoggerProvider(DiagnosticReporter reporter) | ||
{ | ||
_reporter = reporter; | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return new Logger(_reporter, categoryName); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
private sealed class Logger(DiagnosticReporter reporter, string categoryName) : ILogger | ||
{ | ||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull | ||
{ | ||
return null; | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return logLevel >= LogLevel.Warning; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
var kind = logLevel == LogLevel.Warning ? WorkspaceDiagnosticKind.Warning : WorkspaceDiagnosticKind.Failure; | ||
var message = formatter(state, exception); | ||
if (!string.IsNullOrEmpty(categoryName)) | ||
message = $"[{categoryName}] {message}"; | ||
|
||
reporter.Report(new WorkspaceDiagnostic(kind, message)); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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