LocationMy.Application.Log.TraceSource My.Log.TraceSource SyntaxFor 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 DescriptionThe TraceSource property returns an object of type System.Diagnostics.TraceSource that identifies the current configuration of the relevant Log object. Usage at a Glance
ExampleThe 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
See AlsoDefaultFileLogWriter Property, Log Object (My), Log Object (My.Application), WriteEntry Method, WriteException Method |