Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Console.WriteLine in ASP.Net MVC 3

I want to Use Console.writeline in my Asp.net MVC 3 Project. i don't know how to do it. i also try using System.Diagnostics.Debug.WriteLine() method but it also doesn't work. can any one suggest a solution for this

like image 706
Krishan Avatar asked Jul 26 '12 11:07

Krishan


People also ask

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 do I show the console WriteLine in Visual Studio?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console. WriteLine("Debug MyVariable: " + MyVariable) when you get to them.

Where is system diagnostics Debug WriteLine?

Diagnostics. Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug.

What can I use instead of console WriteLine?

You can use a logging library. log4net seems to be the most popular choice.


2 Answers

 Debug.WriteLine("My debug string here");

should do the trick. Check that your application is in debug not release:

debug button

If nothing is coming out on your debug window, right click your project. Select properties. On the left of the opened tab, click Build. There is a check-box "Define DEBUG constant", make sure it is clicked.

enter image description here

You most likely know how to set the debug information to show in the output window (Debug->Windows->Output):

enter image description here

like image 153
Jacob Brewer Avatar answered Sep 20 '22 22:09

Jacob Brewer


What do you want to do specifically?

If you want to output some debug info into the console while your MVC site is running, then I recommend the following:

1) Use System.Diagnostics.Debug.WriteLine()

2) Start the website using Debug (F5 key default, I think..) - and check the Output tab in Visual Studio

This is what I do for a lot of MVC 3/4 apps and it works just fine.

like image 27
Anders Arpi Avatar answered Sep 21 '22 22:09

Anders Arpi