System.Console.WriteLine question

  • Thread starter Thread starter newsgroupie
  • Start date Start date
N

newsgroupie

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" ;-)
 
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]
 
Thomas said:
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.

Couldent you just use System.Diagnostics.Debug.WriteLine for this?
 
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]
 
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
 
newsgroupie said:
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.
 
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
 
newsgroupie said:
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)
 
Back
Top