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?
@Avram's answer has worked for me, except that the single overload in his code wasn't the one that log4net's
ConsoleAppender
was using on my system. (I'm interested inConsole.SetOut
so that log4net'sConsoleAppender
outputs to Visual Studio's "Debug" output pane.) So I overrode all ofStringWriter
'sWrite
andWriteLine
methods acceptingstring
,object
,char[]
, etc. on the assumption that one or more of these was whatConsoleAppender
was calling viaConsole
.This succeeded, and log4net logging now appears in my "Debug" pane.
I'm including the code below for the benefit of anyone with similar goals. (To be entirely safe, one could override the remaining
StringWriter.Write
and.WriteLine
methods.) I've removed the calls tobase
because they appear to be unnecessary, and I think they just build up a large buffer insideStringWriter
(usually accessed via that class's.ToString()
.)Basically the most simple solution look like this.
and you must add to the initialization of program this line "Console.SetOut(new ToDebugWriter());"
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.