views:

1035

answers:

2

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

I find plenty of instructions on how to bet console and debug statements to appear in the output of the Console, but not how to get them to appear in the "Output" window.

Does anyone know?

A: 

If you can get hold of the stream for the output window you can use Console.SetOut() to redirect to it. However this approach doesn't appear to be possible.

System.Debug outputs to every TraceListener in its TraceListenerCollection. There is only one TraceListener registered initially which is the DefaultTraceListener. It does not make use of a stream object and instead uses native methods for output.

An approach that uses the Visual Studio API is probably the way to go.

Alex Angas
+4  A: 

Basically the most simple solution look like this.

    public class ToDebugWriter : StringWriter
    {
        public override void WriteLine(string value)
        {
            Debug.WriteLine(value);
            base.WriteLine(value);
        }
    }

and you must add to the initialization of program this line "Console.SetOut(new ToDebugWriter());"

Avram
Good answer. Thanks!
Quinn Wilson
Damn! I finally can se my NHibernate queries on Visual Studio!
Ciwee