views:

116

answers:

5

I would like to print some traces during the requests processing.

But when I make Console.WriteLine("something") in this environment, nothing is shown.

What is missing, what do I need to do in order to use console to print these traces?

Thanks

+1  A: 

Where are you looking for the output?

Console.WriteLine() writes to the command line - not to the webpage. Either use Response.Write() to write onto the webpage or start up your application in the Visual Studio debugger to look at the command line output.

ctford
I'm looking at the command line / output, none of them shows anything.
Victor Rodrigues
+1  A: 

You can use Response.Write to write output to your page for debugging, or use alert in javascript, or even write to a log file. There are many ways to get debugging output. There's also a log4net for .Net that you can use (similar to log4j)

dcp
+2  A: 

Use Debug.Write() and use the debugger output window.

Alternatively, use the ASP.NET trace feature, which is quite powerful.

CesarGon
Could I create some dedicated output to my app? I found Debug.Write as the best alternative here to do the tracing, but other traces are being done by asp.net there, I only would like to see my traces.
Victor Rodrigues
Yes. Navigate to the `trace.axd` page in your web app's root directory. If tracing is enabled for your app, that page will show the trace messages for your app only.
CesarGon
+2  A: 

Given that it's an ASP.NET application, I would do:

Page.Trace.Write ("Something here");

Then enable trace either for the page or the application and then just go to ~/Trace.axd to see the results (they can also be at the end of the page output, depending on the configuration option that you choose).

Gonzalo
+1  A: 

In addition to the methods already mentioned you can simply write to a log file:

File.AppendAllText(@"c:\log.txt", @"Debug Message Here!" + Environment.NewLine);

Of course you could use Server.MapPath to write the file in your web directory.