将控制台重定向到app.config中的Visual Studio调试输出窗口 [英] Redirect console to Visual Studio debug output window in app.config
问题描述
我想让我的Console.WriteLine()
命令与我的Debug.WriteLine()
语句一起出现在输出"窗口中.我想我已经弄清楚了怎么做一次,但是我不记得/在Google上找到了再做一次的方法.我似乎记得能够在app.config
文件中执行此操作.
I want to get my Console.WriteLine()
commands to appear in my "Output" window with my Debug.WriteLine()
statements. I think I figured out how to do this once, but I can't remember / find on google how to do it again. I seem to remember being able to do this in the app.config
file.
我找到了很多有关如何使控制台和调试语句出现在控制台输出中的说明,而不是如何使它们出现在输出"窗口中的说明.
I find plenty of instructions on how to get console and debug statements to appear in the output of the Console, but not how to get them to appear in the "Output" window.
有可能吗?
推荐答案
基本上,最简单的解决方案是这样的.
Basically the most simple solution looks like this.
public class ToDebugWriter : StringWriter
{
public override void WriteLine(string value)
{
Debug.WriteLine(value);
base.WriteLine(value);
}
}
并且您必须将以下行添加到程序的初始化中:
And you must add this line to the initialization of the program:
Console.SetOut(new ToDebugWriter());
这篇关于将控制台重定向到app.config中的Visual Studio调试输出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!