Getting Diagnostic Output from your Windows Phone programs

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)
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.
But in non-debugging mode, nothing printed...
And debugview can not see anything either.