Fun, Games and Disaster with Console.Writeline

A

Andrew Ducker

We were using Console.Writeline from within our app, to do some routine
debugging.

And then we started having random problems when the code was run by a
tester, on their own machine. We couldn't replicate these problems on
the developer machines.

And then we eventually worked out that on the dev machines Console
output was going to a window, and on the test machines it was
going....nowhere.

Does anyone know where Console.Writeline output goes when there's no
console? Is it being logged to a buffer that eventually overflows,
causing an exception later? Anyone? And if so, is there any way
around this than never, ever using Console.Writeline from a GUI app?

Cheers,

Andy D
 
W

Willy Denoyette [MVP]

Andrew Ducker said:
We were using Console.Writeline from within our app, to do some routine
debugging.

And then we started having random problems when the code was run by a
tester, on their own machine. We couldn't replicate these problems on
the developer machines.

And then we eventually worked out that on the dev machines Console
output was going to a window, and on the test machines it was
going....nowhere.

Does anyone know where Console.Writeline output goes when there's no
console? Is it being logged to a buffer that eventually overflows,
causing an exception later? Anyone? And if so, is there any way
around this than never, ever using Console.Writeline from a GUI app?

Cheers,

Andy D

Console output goes nowhere when no console is attached to the process, that
is when the program is build using /target:WinExe.
Output is not buffered and is simply lost.
So your problems must be searched elsewere.
Note that you should not use Console.Write in UI applications, for debugging
pursposes you should use Debug.Write/WriteLine.

Willy.
 
D

David Browne

Andrew Ducker said:
We were using Console.Writeline from within our app, to do some routine
debugging.

And then we started having random problems when the code was run by a
tester, on their own machine. We couldn't replicate these problems on
the developer machines.

And then we eventually worked out that on the dev machines Console
output was going to a window, and on the test machines it was
going....nowhere.

Does anyone know where Console.Writeline output goes when there's no
console? Is it being logged to a buffer that eventually overflows,
causing an exception later? Anyone? And if so, is there any way
around this than never, ever using Console.Writeline from a GUI app?


Well, I'm not sure what happens to the Console output in a program which
doesn't have a console. I think Console.WriteLine just goes into the bit
bucket.

But you shoudn't use Console.WriteLine in the first place. Use
Trace.WriteLine instead.

In a console program add a TraceListener to output Trace data to the
console, and it will appear there. In a GUI program or a service add a
TraceListener to putput Trace to a file, or a window or whatever. Or attcah
no TraceListener and the output will go into the bit bucket.

David
 
N

Nick Hounsome

David Browne said:
Well, I'm not sure what happens to the Console output in a program which
doesn't have a console. I think Console.WriteLine just goes into the bit
bucket.

But you shoudn't use Console.WriteLine in the first place. Use
Trace.WriteLine instead.

In a console program add a TraceListener to output Trace data to the
console, and it will appear there. In a GUI program or a service add a
TraceListener to putput Trace to a file, or a window or whatever. Or
attcah no TraceListener and the output will go into the bit bucket.

Get the free debugview http://www.sysinternals.com/Utilities/DebugView.html
and you can avoid all the trace listener stuff and get some nice filtering
as well
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top