Closed thegreatco closed 2 years ago
It would be something like this:
public async ValueTask ExecuteAsync(IConsole console)
{
var traceListener = new TextWriterTraceListener(console.Output);
Trace.Listeners.Add(traceListener);
// ...
Trace.Listeners.Remove(traceListener);
}
Or at the application level:
public static async Task<int> Main()
{
var console = new SystemConsole();
var traceListener = new TextWriterTraceListener(console.Output);
Trace.Listeners.Add(traceListener);
return await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
.UseConsole(console)
.Build()
.RunAsync();
}
Details
It would be helpful if we could somehow capture the output written with
System.Diagnostics.Trace
andSystem.Diagnostics.Debug
and have that get written toIConsole
.