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; namespace SharpIDE.Application.Features.Logging;
@@ -11,30 +11,17 @@ public class InternalTerminalLoggerFactory
return logger; 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 = []; string[]? args = [];
bool supportsAnsi = true; bool supportsAnsi = true;
bool outputIsScreen = true; bool outputIsScreen = true;
uint? originalConsoleMode = 0x0007; uint? originalConsoleMode = 0x0007;
object? logger = method.Invoke( var logger = TerminalLogger.CreateTerminalOrConsoleLogger(args, supportsAnsi, outputIsScreen, originalConsoleMode);
obj: null,
parameters: [args, supportsAnsi, outputIsScreen, originalConsoleMode]);
var castLogger = (ILogger)logger!; logger.Parameters = parameters;
castLogger.Parameters = parameters; logger.Verbosity = loggerVerbosity;
castLogger.Verbosity = loggerVerbosity; return logger;
return castLogger;
} }
} }

View File

@@ -19,6 +19,7 @@
<Publicize Include="Microsoft.CodeAnalysis.Workspaces" /> <Publicize Include="Microsoft.CodeAnalysis.Workspaces" />
<Publicize Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" /> <Publicize Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<Publicize Include="Microsoft.VisualStudio.Shared.VSCodeDebugProtocol" IncludeCompilerGeneratedMembers="false" /> <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" /> <DoNotPublicize Include="Microsoft.CodeAnalysis.Workspaces:System.Linq.RoslynEnumerableExtensions" />
</ItemGroup> </ItemGroup>