51

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

1

3 Answers 3

102
 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

Sign up to request clarification or add additional context in comments.

Comments

33

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.

4 Comments

Even when running the website in Debug mode from Visual Studio? Are you sure you are looking at the Output panel?
Okay. And where do you want that output to be displayed?
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.
F5 runs your site in debug mode, whereas ctrl + F5 runs it in build mode, so why is there 2 options? because debug mode runs very slowly & you can't edit your files while running it. So I suggest you watch what you're doing rather then just blindly following whatever everyone is saying.
-1

It's not a console application but a web one. Use internal visual studio debug and quick watches to see what's happening in your program right now. In most production needs you can use some popular logging tools (log4net for ex).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.