Debug Status : Debug « Development « VB.Net Tutorial






Imports System.Diagnostics
Imports System.IO
Module Module1
    Sub Main()
        Dim Str As FileStream
        Dim Listener As TextWriterTraceListener

        If (Debugger.IsAttached) Then
            Console.WriteLine("Debugging")

            Str = New FileStream("C:\DebugMessages.txt", System.IO.FileMode.Append)
            Dim DebugFile As New StreamWriter(Str)
            Listener = New TextWriterTraceListener(DebugFile)
            Debug.Listeners.Add(Listener)
            Debug.AutoFlush = True
        Else
            Console.WriteLine("Not debugging")
        End If


        Debug.WriteLine("")
        Debug.WriteLine("Messages generated at " & Now())
        Debug.WriteLine("In Button Click")
        Debug.WriteLine("Calling First")
        First()
        Debug.WriteLine("Exiting Button Click")

        If (Debugger.IsAttached) Then
            Debug.Listeners.Remove(Listener)
            Str.Close()
            Console.WriteLine("Done")
        End If
    
    End Sub
    Private Sub First()
        Debug.WriteLine("In First")
        Debug.WriteLine("Calling Second")
        Second()
        Debug.WriteLine("Back in First")
    End Sub

    Private Sub Second()
        Debug.WriteLine("In Second")
    End Sub

End Module
Not debugging








7.20.Debug
7.20.1.Convert Debug message to a file
7.20.2.Debug Status
7.20.3.Use Debug.Assert