开发者

How can I get a reference to an output stream that writes to the Visual Studio "output" window?

开发者 https://www.devze.com 2022-12-20 11:40 出处:网络
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 Stu开发者_JS百

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 Stu开发者_JS百科dio 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?


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消