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

System.Console.WriteLine question

P: n/a
Hi Newsgroupies,

I'm writing a Web Forms program using C# (VS.NET 2003) and trying to
monitor it whilst running using "System.Console.WriteLine(<params>)" but
can't for the life of me find where it outputs too.

Am I thick or just unlucky?

Please help!

Lost & Bewildered, UK

Ps: Back in the good old days we had something called "TRACE" ;-)
Nov 16 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Unfortunately I don't think you can use Console. Apparently standard input
and standard output are not mapped to the console for an ASP.NET
application. I would suggest opening a file and writing to the file for
logging purposes. I ran into this issue some time ago. You are not missing
anything.

Thomas P. Skinner [MVP]

"newsgroupie" <ne*********@nospam.com> wrote in message
news:QR**************@rjmeltd.demon.co.uk...
Hi Newsgroupies,

I'm writing a Web Forms program using C# (VS.NET 2003) and trying to
monitor it whilst running using "System.Console.WriteLine(<params>)" but
can't for the life of me find where it outputs too.

Am I thick or just unlucky?

Please help!

Lost & Bewildered, UK

Ps: Back in the good old days we had something called "TRACE" ;-)

Nov 16 '05 #2

P: n/a
Thomas P. Skinner [MVP] wrote:
Unfortunately I don't think you can use Console. Apparently standard input
and standard output are not mapped to the console for an ASP.NET
application. I would suggest opening a file and writing to the file for
logging purposes. I ran into this issue some time ago. You are not missing
anything.

Ps: Back in the good old days we had something called "TRACE" ;-)


Couldent you just use System.Diagnostics.Debug.WriteLine for this?
Nov 16 '05 #3

P: n/a
Yes. This works as long as you run the application under VS.NET under debug
mode. The output from Debug.WriteLine calls goes to the output window. I was
thinking the question was geared more to a type of logging/monitoring rather
than debugging.

I often change the build to a console build for a Windows Forms application
for just such a purpose. When you do that you get a console window that you
can use Console.WriteLine to output to. This works regardless of whether you
run the program from VS.NET or not.

Thomas P. Skinner [MVP]

"Benjamin" <cs************@spamgourmet.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
Thomas P. Skinner [MVP] wrote:
Unfortunately I don't think you can use Console. Apparently standard
input and standard output are not mapped to the console for an ASP.NET
application. I would suggest opening a file and writing to the file for
logging purposes. I ran into this issue some time ago. You are not
missing anything.

Ps: Back in the good old days we had something called "TRACE" ;-)


Couldent you just use System.Diagnostics.Debug.WriteLine for this?

Nov 16 '05 #4

P: n/a
There are various tools out there that let you look at the debug output
stream without having to attach a debugger. Here's one:

http://www.sysinternals.com/ntw2k/fr...ebugview.shtml

But if you want to do logging, then look at the Trace class. Or if you want
a lot of flexibility, consider looking at the log4net project.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"Thomas P. Skinner [MVP]" wrote:
Yes. This works as long as you run the application under VS.NET under
debug mode. The output from Debug.WriteLine calls goes to the output
window. I was thinking the question was geared more to a type of
logging/monitoring rather than debugging.

I often change the build to a console build for a Windows Forms
application for just such a purpose. When you do that you get a console
window that you can use Console.WriteLine to output to. This works
regardless of whether you run the program from VS.NET or not.

Thomas P. Skinner [MVP]

"Benjamin" <cs************@spamgourmet.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
Thomas P. Skinner [MVP] wrote:
Unfortunately I don't think you can use Console. Apparently standard
input and standard output are not mapped to the console for an ASP.NET
application. I would suggest opening a file and writing to the file for
logging purposes. I ran into this issue some time ago. You are not
missing anything.

Ps: Back in the good old days we had something called "TRACE" ;-)


Couldent you just use System.Diagnostics.Debug.WriteLine for this?

Nov 16 '05 #5

P: n/a
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

....And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.

Many thanks in advance,

newsgroupie
Nov 16 '05 #6

P: n/a
newsgroupie <ne*********@nospam.com> wrote:
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

...And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.


So call String.Format yourself:

String.Format ("The function returned {0}", returnValue);

and pass that in as the single argument.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

P: n/a
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

....And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.

Many thanks in advance,

newsgroupie
Nov 16 '05 #8

P: n/a
newsgroupie <ne*********@nospam.com> wrote:
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

...And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.


So call String.Format yourself:

String.Format ("The function returned {0}", returnValue);

and pass that in as the single argument.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9

P: n/a
How do I do the C# equivalent of the MFC code...

int iNumber = 34;

TRACE("The answer is %04d\n", iNumber);

"The answer is 0034"

....i.e. pad the number out with leading spaces? What do I have to add to
this in C#...

System.Diagnostics.Trace.WriteLine( String.Format( "{0}",
iNumber.ToString() ) );

Thanks again,

Newsgroupie

In message <MP************************@msnews.microsoft.com >, Jon Skeet
<?@pobox.com.invalid> writes
newsgroupie <ne*********@nospam.com> wrote:
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

...And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.


So call String.Format yourself:

String.Format ("The function returned {0}", returnValue);

and pass that in as the single argument.

Nov 16 '05 #10

P: n/a
How do I do the C# equivalent of the MFC code...

int iNumber = 34;

TRACE("The answer is %04d\n", iNumber);

"The answer is 0034"

....i.e. pad the number out with leading spaces? What do I have to add to
this in C#...

System.Diagnostics.Trace.WriteLine( String.Format( "{0}",
iNumber.ToString() ) );

Thanks again,

Newsgroupie

In message <MP************************@msnews.microsoft.com >, Jon Skeet
<?@pobox.com.invalid> writes
newsgroupie <ne*********@nospam.com> wrote:
Hi Newsgroupies!

Thanks for all your help but what I really want to do is something like
we could do in the good old days with MFC, ie...

TRACE("The function returned %d\n", iReturnValue);

...And be able to see this in the output window.

I appreciate that .Debug & .Trace do a similar thing in C# but without
arguments as above.


So call String.Format yourself:

String.Format ("The function returned {0}", returnValue);

and pass that in as the single argument.

Nov 16 '05 #11

P: n/a
newsgroupie <ne*********@nospam.com> wrote:
How do I do the C# equivalent of the MFC code...

int iNumber = 34;

TRACE("The answer is %04d\n", iNumber);

"The answer is 0034"

...i.e. pad the number out with leading spaces? What do I have to add to
this in C#...

System.Diagnostics.Trace.WriteLine( String.Format( "{0}",
iNumber.ToString() ) );


Use String.Format ("{0:d4}", iNumber)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #12

P: n/a
newsgroupie <ne*********@nospam.com> wrote:
How do I do the C# equivalent of the MFC code...

int iNumber = 34;

TRACE("The answer is %04d\n", iNumber);

"The answer is 0034"

...i.e. pad the number out with leading spaces? What do I have to add to
this in C#...

System.Diagnostics.Trace.WriteLine( String.Format( "{0}",
iNumber.ToString() ) );


Use String.Format ("{0:d4}", iNumber)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.