如何获取写入 Visual Studio“输出”的输出流的引用?窗户?

发布于 2024-08-21 14:46:54 字数 297 浏览 3 评论 0原文

我有一个第三方 .NET 库,可以将一些关键诊断信息输出到 TextWriter 实例。我希望在调试模式下将此信息转储到 Visual Studio 2008 的输出窗口,如果不在调试模式下则忽略此信息。有什么方法可以获取对使用此输出窗口的输出流的引用,以便我可以创建一个使用它的 TextWriter

要使用控制台进行输出,我可以这样做...

foo.LogTo(Console.Out);

使用此接口,我可以将日志信息发送到输出窗口吗?

I have a third-party .NET library that enables output of some key diagnostic information to a TextWriter instance. I'd like to have this information dumped to the output window of Visual Studio 2008 while in debug mode and ignored if not in debug mode. Is there any way I can get a reference to an output stream that uses this output window so I can create a TextWriter that uses it?

To use the console for output, I can do...

foo.LogTo(Console.Out);

Using this interface, can I get log info sent to the output window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残龙傲雪 2024-08-28 14:46:54

Visual Studio 允许将消息写入输出窗口从 .NET 1.1 开始通过 Debug 类

话虽如此,创建您自己的 TextWriter 实现非常容易,该实现只需将调用转发到 Debug 类上的适当方法。当内容写入 TextWriter 时,您将调用 Debug 类方法,它将出现在输出窗口中。

另外,由于您正在调用 Debug 类,因此当您未处于调试模式时,不会输出输出(因为 Debug 类方法上的条件 属性)。

Visual Studio has allowed for the writing of messages to the output window through the Debug class since .NET 1.1.

With that said, it's easy enough to create your own TextWriter implementation which would just forward calls to the appropriate methods on the Debug class. When the content is written to your TextWriter, you would call the Debug class method and it will appear in the output window.

Also, because you are making the calls to the Debug class, when you are not in debug mode, the output wont be output (because of the Conditional attribute on the methods of the Debug class).

棒棒糖 2024-08-28 14:46:54

您可以使用 OutputDebugString API 创建自己的 TextWriter 派生类使用 Debug.WriteLine() 转发数据。

You can create your own TextWriter derived class, using the OutputDebugString API or use Debug.WriteLine() to forward the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文