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 ");