views:

104

answers:

1

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?

+1  A: 

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

casperOne
Thanks... I guess I hadn't really considered the obvious of creating a TextWriter of my own that just delegated to Debug.WriteLine, but I think that's relatively straightforward and probably what I will end up doing.
Chris Farmer