Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Unblocking Files from the Internet | Main | Mystery Object Answer »
Tuesday
Aug102010

Getting Diagnostic Output from your Windows Phone programs

Birthday Phone

It is often very useful to find out what your programs are doing. You can put breakpoints into your code, but sometimes you just want print messages. If you are writing Windows Phone apps this is very easy, but it doesn’t use the Console.WriteLine that you might be used to. You can get messages from your Windows Phone program (even when it is running in the device) by using:

System.Diagnostics.Debug.WriteLine ("Your Message Here ");

The output appears in the Output window in Visual Studio 2010  (remember to ask it to show you output from the Debug stream). The best way to control debug output is to use conditional compilation to switch your debug statements on and off:

// Put this at the top of the program to turn debugging on
#define Debug

#ifdef Debug
System.Diagnostics.Debug.WriteLine ("Debug Message Here ");
#endif

Reader Comments (3)

The Debug class is quite handy!

You should note that it is not necessary to surround the Debug.WriteLine calls with the #ifdef Debug statements. The Debug class is marked with the ConditionalAttribute and it will therefore only be used if the Debug symbol is defined.

So for a regular Debug build the Debug.WriteLine will run as usual while for a Release build the call will be ignored.
August 11, 2010 | Unregistered CommenterRune Grimstad
Is it bad I noticed the Tapitillo hot sauce before I read the post?
August 12, 2010 | Unregistered CommenterCameron Wilby
function Debug.WriteLine() output strings to "debug output" window in VS2010 in debugging mode.
But in non-debugging mode, nothing printed...

And debugview can not see anything either.
November 23, 2010 | Unregistered Commenterfeifan

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.