当前位置: 首页>>代码示例>>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;未经允许,请勿转载。