Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Console.WriteLine in ASP.NET (C#) during debug?

I want to write some result to the console in ASP.NET (C#). It works in a Window application, but a Web application does not work. Here is what I have tried:

protected void btonClick_Click(object sender, EventArgs e) {     Console.WriteLine("You click me ...................");     System.Diagnostics.Debug.WriteLine("You click me ..................");     System.Diagnostics.Trace.WriteLine("You click me .................."); } 

But I see nothing in the Output panel. How do I solve this problem?

like image 388
Leap Bun Avatar asked Mar 08 '12 07:03

Leap Bun


People also ask

What is console WriteLine () in C#?

WriteLine(String, Object, Object) Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

Where does console WriteLine go C#?

It goes to the console (standard output) or to the stream that the console is set to.

How do I show console WriteLine Output in my browser console?

You can use Debug. Writeline("debug information") . It will be displayed in the Output window.

How does console readline work in C#?

The C# readline method is mainly used to read the complete string until the user presses the Enter key or a newline character is found. Using this method, each line from the standard data input stream can be read. It is also used to pause the console so that the user can take a look at the output.


1 Answers

Console.Write will not work in ASP.NET as it is called using the browser. Use Response.Write instead.

See Stack Overflow question Where does Console.WriteLine go in ASP.NET?.

If you want to write something to Output window during debugging, you can use

System.Diagnostics.Debug.WriteLine("SomeText"); 

but this will work only during debug.

See Stack Overflow question Debug.WriteLine not working.

like image 165
PraveenVenu Avatar answered Oct 05 '22 03:10

PraveenVenu