Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 531
Chris Farmer Avatar asked Nov 05 '22 16:11

Chris Farmer


1 Answers

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

like image 56
casperOne Avatar answered Nov 15 '22 12:11

casperOne