9

So I was wondering, when running a regular winforms application, where does the Console.WriteLine() method write to?

I know that during debug it'll happily spit out all text in the debug output, but where does everything go when I'm no longer debugging and using the program like an end-user would? Does it go into some kind of cache? The depths of RAM? On vacation to Latvia?

And if it writes to something that's accessible during runtime, can we somehow show it to the user or write everything down to a textfile or something?

3 Answers3

7

Are you talking about Console.WriteLine or Debug.WriteLine?

Console.WriteLine works in the same way under debug and release configuration. If you configure your project like Console Application and start it in release mode, you'll get first a console in background where you'll see all your outputs.This is a Winform Project configured to run as console project and writes "Hello World" in form load event

Debug.WriteLine has a conditional statement, if DEBUG is not defined. It doesn't write anything.

Montag451
  • 1,168
  • 3
  • 14
  • 30
Oscar
  • 13,594
  • 8
  • 47
  • 75
1

Console.WriteLine() will write on the standard output in debug or release mode. So you have a way to catch it in release mode.

There's an alternative with Debug.WriteLine that, if I remember, isn't compiled in release.

3wic
  • 500
  • 6
  • 22
1

I think your question is really about wanting to capture Console.WriteLine(). First, Console.WriteLine() writes to the standard output stream which can be read by attaching a console window or through other means of intercepting the stream.

If you want to capture debug or logging information you want to use

System.Diagnostics.Trace.WriteLine

Then, to send your output to a file you could setup a TraceListener which could be a file or something.

Brad Rem
  • 6,036
  • 2
  • 25
  • 50
  • 1
    That's not necessarily true. One can read from standard output without needing to use a console window. It could, for example, be read by a launcher program that uses `Process.Start` to run it and then access the standard input/output. – Servy Jun 20 '13 at 15:44
  • @Servy, OK, I've updated my answer which I hope is more accurate. – Brad Rem Jun 20 '13 at 15:47