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

89

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?

This question is tagged with c# asp.net visual-studio-2010 console

~ Asked on 2012-03-08 07:30:06

The Best Answer is


187

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.

~ Answered on 2012-03-08 07:34:16


28

using System.Diagnostics;

The following will print to your output as long as the dropdown is set to 'Debug' as shown below.

Debug.WriteLine("Hello, world!");


enter image description here

~ Answered on 2012-03-08 07:40:02


Most Viewed Questions: