The FAIL method cannot prevent the application from running, and they only output an error message. WRITE and WRITELINE methods are written to a message. They differ only after the latter output is executed and then output. Finally, the Flush method refreshes the cache. The Flush method has a function of the device that tracks the information output (eg, flow). You can use Auto Refresh - Automatically refresh the listener after each message. You can configure in the configuration file:
configure>
As you can see, if you create your own listener, you need to implement at least Write (String) and WriteLine (String) method (these methods are abstract methods).
Microsoft offers three tracking listeners: DefaultTracelistener, EventLogTraceListener, and TextWritetracelister .. The first listener has a default method (if the application runs in the environment of the command line, then output information to the console. If the application is in debugging, output to the window). The second listener output information is in the specified event log (based on NT Technology - Winnt, 2K, XP or .NET). The third listener outputs the text to the stream.
Active Listener list can be set in programming or in the configuration file. The default includes DefaultTracelistener.
Programming changes the list of activities to manage the listeners collection (by adding and deleting methods). Manage the listener in the configuration file, you want to use the following syntax:
Initializedata = "c: /mylistener.log" /> listeners> trace> configure> The initializedat parameter is a string parameter passing to the constructor (specifying the EventLogTraceListener listener event log). The listener is familiar with the creation application to use the listener to output tracking information. The code is simple: // Trace Listener Demo // // purpose: To Demonstrate How To Use Listener Using system; Using system.diagnostics; Namespace assertion { Class Application { [Stathread] Static void main (string [] args) { Trace.Writeline ("Calling WriteLine Method", "Trace Listener Demo"); TRACE.FLUSH (); } } } These codes are not enough, we must create a configuration file to set the listener: Initializedata = "mylistener.log" /> Initializedata = "Application" /> listeners> trace> configure> This profile deletes the default listener to join two custom listeners: the first output information to text files, the second output to the event log. For the first listener INITIDATA property specifies the file, the second listener log event to the event log. Run the program. Check the first listener, you can see the MyListener.log file, which contains the following information: Tracing Listener Demo: Calling WriteLine Method The first listener writes the information into a text file. View the second. Open Microsoft Console Browse Application Logs in the Event View (this is specified in the configuration file). Here you can see the event information of our application. More possible, on this list is the top. If you double click, you can see the content. We find the following information: It is easier to read when the output information is read: Sometimes the application is complicated, and the tracking information can be formatted for easy understanding. Make the output information more beautiful, you can use a zoom, look at the simple code below: Public void calee () { Trace.WRTELINE ("Callee Started"); ... // Some INTERNAL LOGIC Trace.writeline ("Initializing Buffer"); ... // Some Extra INTERNAL LOGIN Trace.writeline ("exiting callee"); } Public void caler () { Trace.write ("Caller Called"); ... ..// Some External Logic Callee (); ... ..// Some Extral Logic Trace.writeline ("Initializing Buffer"); Trace.write ("exiting caller"); } The output information is as follows: Caller Called Callee star Initializing Buffer, INITIALIZING BUFFER EXITING CALLEE Initializing Buffer, INITIALIZING BUFFER EXITING CALLER If the method does not display information before and after execution, we will be confused by the initialization cache information of these copies. In addition to the information display is unclear. To avoid unclear, we use the TRACE supported indentation. Modified code, use indentation: Public void calee () { Trace.indent (); trace.writeline ("Callee Started"); ... ..// Some Internal Logic Trace.writeline ("Initializing Buffer"); ....// Some Extra InterNal Logic Trace.writeline ("exiting callee"); Trace.unundent (); } Public void caler () { Trace.write ("Caller Called"); ....// Some External Logic Callee (); ....// Some Extra Login Trace.writeline ("Initiallizing Buffer"); Trace.write ("exiting caller"); } The output information is as follows: Caller Called Callee Started Initializing buffer EXITING CALLEE Initializing buffer EXITING CALLER As you can see, the callee method outputs indentation, it is easy to separate information from different methods. The Indent and Unidentent methods can be called to achieve the purpose of separation information. Modify the tracking configuration in the configuration file: configure>