當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET TextWriterTraceListener構造函數代碼示例

本文整理匯總了VB.NET中System.Diagnostics.TextWriterTraceListener.TextWriterTraceListener構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET TextWriterTraceListener構造函數的具體用法?VB.NET TextWriterTraceListener怎麽用?VB.NET TextWriterTraceListener使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Diagnostics.TextWriterTraceListener的用法示例。


在下文中一共展示了TextWriterTraceListener構造函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Sample

Public Class Sample
    
    Public Shared Sub Main()
        ' Create a text writer that writes to the console screen and add
        ' it to the trace listeners 
        Dim myWriter As New TextWriterTraceListener()
        myWriter.Writer = System.Console.Out
        Trace.Listeners.Add(myWriter)
        
        ' Write the output to the console screen.
        myWriter.Write("Write to the Console screen. ")
        myWriter.WriteLine("Again, write to console screen.")
        
        ' Flush and close the output.
        myWriter.Flush()
        myWriter.Close()
    End Sub

End Class
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:19,代碼來源:TextWriterTraceListener

示例2: TWTLConStreamMod

' 導入命名空間
Imports System.Diagnostics
Imports System.IO

Module TWTLConStreamMod

    ' args(0) is the specification of the trace log file.
    Sub Main(ByVal args() As String)

        ' Verify that a parameter was entered.
        If args.Length = 0 Then
            Console.WriteLine("Enter a trace file specification.")

        Else
            ' Create a stream object.
            Dim traceStream As FileStream
            Try
                traceStream = New FileStream( _
                    args(0), FileMode.Append, FileAccess.Write)
            Catch ex As Exception
                Console.WriteLine( _
                    "Error creating FileStream for trace file ""{0}"":" & _
                    vbCrLf & "{1}", args(0), ex.Message)
                Return
            End Try

            ' Create a TextWriterTraceListener object that takes a stream.
            Dim textListener As TextWriterTraceListener
            textListener = New TextWriterTraceListener(traceStream)
            Trace.Listeners.Add(textListener)

            ' Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine( _
                "This is trace listener named """ & textListener.Name & """")
            textListener.WriteLine( _
                "Trace written through a stream to: " & _
                vbCrLf & "    """ & args(0) & """")

            ' Write a message to all trace listeners.
            Trace.WriteLine(String.Format( _
                "This trace message written {0} to all listeners.", Now))

            ' Flush and close the output.
            Trace.Flush()
            textListener.Flush()
            textListener.Close()
        End If
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:49,代碼來源:TextWriterTraceListener

示例3: TextWriterTraceListenerSample

#Const TRACE=True

Imports System.IO
Imports System.Diagnostics

Public Class TextWriterTraceListenerSample
   
   Public Shared Sub Main()
      Dim myTextListener As TextWriterTraceListener = Nothing

      ' Create a file for output named TestFile.txt.
      Dim myFileName As String = "TestFile.txt"
      Dim myOutputWriter As New StreamWriter(myFileName, True)
 
      ' Add a TextWriterTraceListener for the file.
      myTextListener = New TextWriterTraceListener(myOutputWriter)
      Trace.Listeners.Add(myTextListener)
     
      ' Write trace output to all trace listeners.
      Trace.WriteLine(DateTime.Now.ToString() + " - Trace output")
      
      ' Remove and close the file writer/trace listener.
      myTextListener.Flush()
      Trace.Listeners.Remove(myTextListener)
      myTextListener.Close()

   End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:28,代碼來源:TextWriterTraceListener

示例4: TWTLConStringMod

' 導入命名空間
Imports System.Diagnostics

Module TWTLConStringMod

    ' args(0) is the specification of the trace log file.
    Sub Main(ByVal args() As String)

        ' Verify that a parameter was entered.
        If args.Length = 0 Then
            Console.WriteLine("Enter a trace file specification.")

        Else
            ' Create a TextWriterTraceListener object that takes a 
            ' file specification.
            Dim textListener As TextWriterTraceListener
            Try
                textListener = New TextWriterTraceListener(args(0))
                Trace.Listeners.Add(textListener)
            Catch ex As Exception
                Console.WriteLine( _
                    "Error creating TextWriterTraceListener for trace " & _
                    "file ""{0}"":" & vbCrLf & "{1}", args(0), ex.Message)
                Return
            End Try

            ' Write these messages only to the TextWriterTraceListener.
            textListener.WriteLine( _
                "This is trace listener named """ & textListener.Name & """")
            textListener.WriteLine("Trace written to a file: " & _
                vbCrLf & "    """ & args(0) & """")

            ' Write a message to all trace listeners.
            Trace.WriteLine(String.Format( _
                "This trace message written {0} to all listeners.", Now))

            ' Flush and close the output.
            Trace.Flush()
            textListener.Flush()
            textListener.Close()
        End If
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:43,代碼來源:TextWriterTraceListener

示例5: TWTLConStreamNameMod

' 導入命名空間
Imports System.Diagnostics
Imports System.IO

Module TWTLConStreamNameMod

    Const LISTENER_NAME As String = "myStreamListener"

    ' args(0) is the specification of the trace log file.
    Sub Main(ByVal args() As String)

        ' Verify that a parameter was entered.
        If args.Length = 0 Then
            Console.WriteLine("Enter a trace file specification.")

        Else
            ' Create a stream object.
            Dim traceStream As FileStream
            Try
                traceStream = New FileStream( _
                    args(0), FileMode.Append, FileAccess.Write)
            Catch ex As Exception
                Console.WriteLine( _
                    "Error creating FileStream for trace file ""{0}"":" & _
                    vbCrLf & "{1}", args(0), ex.Message)
                Return
            End Try

            ' Create a TextWriterTraceListener object that takes a stream.
            Dim textListener As TextWriterTraceListener
            textListener = _
                New TextWriterTraceListener(traceStream, LISTENER_NAME)
            Trace.Listeners.Add(textListener)

            ' Write these messages only to the TextWriterTraceListener.
            textListener.WriteLine( _
                "This is trace listener named """ & textListener.Name & """")
            textListener.WriteLine( _
                "Trace written through a stream to: " & _
                vbCrLf & "    """ & args(0) & """")

            ' Write a message to all trace listeners.
            Trace.WriteLine(String.Format( _
                "This trace message written {0} to all listeners.", Now))

            ' Flush and close the output.
            Trace.Flush()
            textListener.Flush()
            textListener.Close()
        End If
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:52,代碼來源:TextWriterTraceListener

示例6: TWTLConWriterNameMod

' 導入命名空間
Imports System.Diagnostics
Imports System.IO

Module TWTLConWriterNameMod

    Const LISTENER_NAME As String = "myWriterListener"

    ' args(0) is the specification of the trace log file.
    Sub Main(ByVal args() As String)

        ' Verify that a parameter was entered.
        If args.Length = 0 Then
            Console.WriteLine("Enter a trace file specification.")

        Else
            ' Create a StreamWriter object that supports appending.
            Dim traceWriter As StreamWriter
            Try
                traceWriter = New StreamWriter(args(0), True)
            Catch ex As Exception
                Console.WriteLine( _
                    "Error creating StreamWriter for trace file ""{0}"":" & _
                    vbCrLf & "{1}", args(0), ex.Message)
                Return
            End Try

            ' Create a TextWriterTraceListener that takes a StreamWriter.
            Dim textListener As TextWriterTraceListener
            textListener = _
                New TextWriterTraceListener(traceWriter, LISTENER_NAME)
            Trace.Listeners.Add(textListener)

            ' Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine( _
                "This is trace listener named """ & textListener.Name & """")
            textListener.WriteLine( _
                "Trace written through a stream to: " & _
                vbCrLf & "    """ & args(0) & """")

            ' Write a message to all trace listeners.
            Trace.WriteLine(String.Format( _
                "This trace message written {0} to all listeners.", Now))

            ' Flush and close the output.
            Trace.Flush()
            textListener.Flush()
            textListener.Close()
        End If
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:51,代碼來源:TextWriterTraceListener

示例7: TWTLConStringNameMod

' 導入命名空間
Imports System.Diagnostics

Module TWTLConStringNameMod

    Const LISTENER_NAME As String = "myStringListener"

    ' args(0) is the specification of the trace log file.
    Sub Main(ByVal args() As String)

        ' Verify that a parameter was entered.
        If args.Length = 0 Then
            Console.WriteLine("Enter a trace file specification.")

        Else
            ' Create a TextWriterTraceListener object that takes a 
            ' file specification.
            Dim textListener As TextWriterTraceListener
            Try
                textListener = _
                    New TextWriterTraceListener(args(0), LISTENER_NAME)
                Trace.Listeners.Add(textListener)
            Catch ex As Exception
                Console.WriteLine( _
                    "Error creating TextWriterTraceListener for trace " & _
                    "file ""{0}"":" & vbCrLf & "{1}", args(0), ex.Message)
                Return
            End Try

            ' Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine( _
                "This is trace listener named """ & textListener.Name & """")
            textListener.WriteLine("Trace written to a file: " & _
                vbCrLf & "    """ & args(0) & """")

            ' Write a message to all trace listeners.
            Trace.WriteLine(String.Format( _
                "This trace message written {0} to all listeners.", Now))

            ' Flush and close the output.
            Trace.Flush()
            textListener.Flush()
            textListener.Close()
        End If
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Diagnostics,代碼行數:46,代碼來源:TextWriterTraceListener


注:本文中的System.Diagnostics.TextWriterTraceListener.TextWriterTraceListener構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。