是否有任何内置功能可以将 Console.WriteLine 调用重定向到 System.Diagnostic.Debug-calls?
我希望有这样的事情:
public static void CallNastyConsoleWriteLineUsingFunction() {
Console.WriteLine(GetImportantInformation());
}
[...]
var writer = DebugTextWriter();
TextWriter stdout = Console.Out;
try
{
Console.SetOut(writer);
CallNastyConsoleWriteLineUsingFunction();
}
finally
{
Console.SetOut(stdout);
}
甚至可能:
using(new ConsoleToDebugRedirector())
{
CallNastyConsoleWriteLineUsingFunction();
}