Simplify terminal logger creation

This commit is contained in:
Matt Parker
2025-11-13 00:06:17 +10:00
parent 087e32baaa
commit f0b45115dd
2 changed files with 8 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
namespace SharpIDE.Application.Features.Logging;
@@ -11,30 +11,17 @@ public class InternalTerminalLoggerFactory
return logger;
}
public static ILogger CreateLogger(string parameters, LoggerVerbosity loggerVerbosity)
private static ILogger CreateLogger(string parameters, LoggerVerbosity loggerVerbosity)
{
var type = Type.GetType("Microsoft.Build.Logging.TerminalLogger, Microsoft.Build");
if (type == null) throw new Exception("TerminalLogger type not found");
var method = type.GetMethod(
"CreateTerminalOrConsoleLogger",
BindingFlags.NonPublic | BindingFlags.Static);
if (method == null) throw new Exception("CreateTerminalOrConsoleLogger method not found");
string[]? args = [];
bool supportsAnsi = true;
bool outputIsScreen = true;
uint? originalConsoleMode = 0x0007;
object? logger = method.Invoke(
obj: null,
parameters: [args, supportsAnsi, outputIsScreen, originalConsoleMode]);
var logger = TerminalLogger.CreateTerminalOrConsoleLogger(args, supportsAnsi, outputIsScreen, originalConsoleMode);
var castLogger = (ILogger)logger!;
castLogger.Parameters = parameters;
castLogger.Verbosity = loggerVerbosity;
return castLogger;
logger.Parameters = parameters;
logger.Verbosity = loggerVerbosity;
return logger;
}
}

View File

@@ -19,6 +19,7 @@
<Publicize Include="Microsoft.CodeAnalysis.Workspaces" />
<Publicize Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<Publicize Include="Microsoft.VisualStudio.Shared.VSCodeDebugProtocol" IncludeCompilerGeneratedMembers="false" />
<Publicize Include="Microsoft.Build" MemberPattern="^Microsoft.Build.Logging\.TerminalLogger\..*" />
<DoNotPublicize Include="Microsoft.CodeAnalysis.Workspaces:System.Linq.RoslynEnumerableExtensions" />
</ItemGroup>