By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

Sending output to a console window in Windows App

P: n/a
Hi All

Java has a facility where you can send output to a DOS window using
System.out.println. This is useful while developing as you can see
what it going in your code.

Does .Net provide a similar facility? I notice that when a Windows app
runs there is an output window that contains messages from the
compiler etc. Is it possible to 'plug' into this?

Any help would be appreciated..

Regards

Paul Bowman
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It does indeed

Console.WriteLine("Hello World");

If you run a windows program the output will be sent to the "Output"
window in Visual Studio

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2

P: n/a
The framework has two good classes for what you are trying to accomplish in
the System.Diagnostics namespace:

o Trace - if you want to continue to produce trace statements in production
o Debug - if you only need debugging information while in development and do
not want that code executed in production.

Using them is simple. For example: "Trace.WriteLine("In Load_Form");" will
write "In Load_Form" to the output window in VS. In addition to uncondional
write statements there are also conditional methods, such as WriteLineIf,
Assert.

What is neat about the classes is that you can also hook up a listener to
record the tracing information in a text file or the event log. You could
control, if a permanent trace is written to file by a configuration setting
in the app.config file and thereby build tracing tools into production apps
that you can turn on and off.

To write all Trace.WriteLine message to a text file you only need the
following code:

System.IO.FileStream fsLog = new System.IO.FileStream("C:\Log\applog.txt",
System.IO.FileMode.OpenOrCreate);
TextWriterTraceListener listener = new TextWriterTraceListener(fsLog);
Trace.Listeners.Add(listener);

You might have to control how often the information is written to disk, you
pretty much have two choices for that. Either manually flushing or
autoflushing to disk. To manually flush the log out, use Trace.Flush() or
automate it with Trace.AutoFlush = true;

If you want more information about it I would recommend looking into the
MCAD/MCSD certification books. I really like them since for an experienced
programmer that is jumping into .NET they have a nice pace compared to the
21 day books.

Hope this helps

Robert Sentgerath

"Paul Bowman" <pa**************@yahoo.co.uk> wrote in message
news:ff**************************@posting.google.c om...
Hi All

Java has a facility where you can send output to a DOS window using
System.out.println. This is useful while developing as you can see
what it going in your code.

Does .Net provide a similar facility? I notice that when a Windows app
runs there is an output window that contains messages from the
compiler etc. Is it possible to 'plug' into this?

Any help would be appreciated..

Regards

Paul Bowman

Nov 15 '05 #3

P: n/a
Thanks Guys!! - Just what I wanted!

Regards Paul Bowman

"Robert Sentgerath" <rs*********@landstar.com> wrote in message news:<OE**************@TK2MSFTNGP11.phx.gbl>...
The framework has two good classes for what you are trying to accomplish in
the System.Diagnostics namespace:

o Trace - if you want to continue to produce trace statements in production
o Debug - if you only need debugging information while in development and do
not want that code executed in production.

Using them is simple. For example: "Trace.WriteLine("In Load_Form");" will
write "In Load_Form" to the output window in VS. In addition to uncondional
write statements there are also conditional methods, such as WriteLineIf,
Assert.

What is neat about the classes is that you can also hook up a listener to
record the tracing information in a text file or the event log. You could
control, if a permanent trace is written to file by a configuration setting
in the app.config file and thereby build tracing tools into production apps
that you can turn on and off.

To write all Trace.WriteLine message to a text file you only need the
following code:

System.IO.FileStream fsLog = new System.IO.FileStream("C:\Log\applog.txt",
System.IO.FileMode.OpenOrCreate);
TextWriterTraceListener listener = new TextWriterTraceListener(fsLog);
Trace.Listeners.Add(listener);

You might have to control how often the information is written to disk, you
pretty much have two choices for that. Either manually flushing or
autoflushing to disk. To manually flush the log out, use Trace.Flush() or
automate it with Trace.AutoFlush = true;

If you want more information about it I would recommend looking into the
MCAD/MCSD certification books. I really like them since for an experienced
programmer that is jumping into .NET they have a nice pace compared to the
21 day books.

Hope this helps

Robert Sentgerath

"Paul Bowman" <pa**************@yahoo.co.uk> wrote in message
news:ff**************************@posting.google.c om...
Hi All

Java has a facility where you can send output to a DOS window using
System.out.println. This is useful while developing as you can see
what it going in your code.

Does .Net provide a similar facility? I notice that when a Windows app
runs there is an output window that contains messages from the
compiler etc. Is it possible to 'plug' into this?

Any help would be appreciated..

Regards

Paul Bowman

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.