TraceSource Property


TraceSource Property

Location

My.Application.Log.TraceSource

My.Log.TraceSource

Syntax

For client applications:

     Dim result As System.Diagnostics.TraceSource = _        My.Application.Log.TraceSource 

For ASP.NET applications:

     Dim result As System.Diagnostics.TraceSource = My.Log.TraceSource 

Description

The TraceSource property returns an object of type System.Diagnostics.TraceSource that identifies the current configuration of the relevant Log object.

Usage at a Glance

  • This property is read-only.

  • Diagnostic content written using the various Debug.Write methods is not sent to the trace listeners.

  • This property is only valid in client and ASP.NET applications. For client applications, use My.Application.Log.TraceSource. For ASP.NET applications, use My.Log.TraceSource.

Example

The following code adds a text file output method to the collection of listeners. As a result, all Debug.Write and similar methods will not only send the output to the Output Window (the default listener) but also to the text file.

     ' ----- Uses "Imports System.IO" above.     ' ----- Define a new listener object.     Dim fileTrace As New TextWriterTraceListener(  )     ' ----- Since the listener is generic and doesn't have any     '       specific destination, the code needs to create the     '       destination and associate it with the listener. In     '       this case, the destination will be a file stream.     Dim traceStream As FileStream = New FileStream("c:\log.txt", _        FileMode.Append, FileAccess.Write)     fileTrace.Writer = New StreamWriter(traceStream)     ' ----- Now the listener is ready to be used.     My.Application.Log.TraceSource.Listeners.Add(fileTrace)     ' ----- Add an entry to the log.     My.Application.Log.WriteEntry("Diagnostic status line 1.")     ' ----- Test complete. Close all opened resources.     My.Application.Log.TraceSource.Listeners.Remove(fileTrace)     fileTrace.Close(  )     traceStream.Close(  )     ' ----- This Debug statement goes only to the Output Window. My.Application.Log.WriteEntry("Diagnostic status line 2.") 

Related Framework Entries

  • Microsoft.VisualBasic.Logging.Log.TraceSource Property

  • System.Diagnostics.TraceSource Class

See Also

DefaultFileLogWriter Property, Log Object (My), Log Object (My.Application), WriteEntry Method, WriteException Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net