Saturday, March 15, 2008

Debug.WriteLine

When it is necessary to write a debug information for debug purposes only, then it is suggested to use method Debug.WriteLine, which writes information to Visual Studio (VS) "Output" window or to any debugger (for example, WinDebug)  "Output" window. It is a very important, that in Release mode, Debug.WriteLine is ignored.

using System.Diagnostics;

namespace DebugSamples
{
    class Program
   
{
        static void Main(string[] args)
        {
            Debug.WriteLine("Debug.Sample.Main(); start", "Trace");
            // ...
           
Debug.WriteLine("Debug.Sample.Main(); finish", "Trace");
        }
    }
}

Visual Studio "Output" window

VS_output

WinDebug "Output" window

WinDbg_output

Reference:

Debug..::.WriteLine Method

How to trace and debug in Visual C#

No comments: