Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to debug a method and need to trace how a variable is being changed to see where I went wrong. What in ASP.NET/C# could I use to do this?

For example if it was php I could stick an echo where ever I need to check the value and it would print it to the html. JavaScript I could use alert(var);

share|improve this question
1  
Can't you use normal debug in Visual Studio? Set a breakpoint in left margin and hit F5. You could also use SPLog ( msdn.microsoft.com/en-us/library/… ) and keep an eye on ULS. –  eirikb Sep 6 '12 at 20:16

2 Answers 2

up vote 1 down vote accepted

When on a developing machine set a break point and simply use the debug option of Visual Studio. Enable "Tracing" might also be a valuable topic to read into.

If not on a developing machine. Consider into using a logging framework. There are several free frameworks available in .NET that are highly configurable.

When in a SharePoint context consider logging errors to the ULS or the event viewer.

share|improve this answer

I usually just write the value to a label on the page.

Page:

<asp:Label ID="test" runat="server" />

Code-Behind:

test.Text = myVar.ToString();

-OR-

test.Text = "myVar: " + myVar.ToString();
share|improve this answer
    
This works well for our team on smaller projects as well. –  Aaron Sep 7 '12 at 14:14
    
I only use this in situations where I can't use the VS debugger, but it's quick and easy. Used to do this a lot more with classic ASP apps... –  RJ Cuthbertson Sep 7 '12 at 15:12
    
Yes, we use it in situations where we are testing on a server without VS installed (Test, Prod) and setting up a custom logging solution is more hassle than it's worth. –  Aaron Sep 7 '12 at 15:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.