Simplify terminal logger creation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user