EventLogTraceListener Class
Assembly: System (in system.dll)
An instance of this EventLogTraceListener can be added to the Debug.Listeners or Trace.Listeners collections to redirect output from tracing or debugging to an EventLog.
The class provides the EventLog property to get or set the event log that receives the tracing or debugging output, and the Name property to hold the name of the EventLogTraceListener.
The Close method closes the event log so it no longer receives tracing or debugging output. The Write and WriteLine methods write a message to the event log.
Note: |
|---|
| To avoid the possibility of writing large amounts of data to the event log, the EventLogTraceListener does not output the optional trace data specified by the TraceOutputOptions property. |
| Topic | Location |
|---|---|
| Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing | Building ASP .NET Web Applications |
| Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing | Building ASP .NET Web Applications |
The following example creates a trace listener that sends output to an event log. First, the code creates a new EventLogTraceListener that uses the source myEventLogSource. Next, myTraceListener is added to the Trace.Listeners collection. Finally, the example sends a line of output to the Listeners object.
public static void Main(string[] args) { // Create a trace listener for the event log. EventLogTraceListener myTraceListener = new EventLogTraceListener("myEventLogSource"); // Add the event log trace listener to the collection. Trace.Listeners.Add(myTraceListener); // Write output to the event log. Trace.WriteLine("Test output"); }
public static void main(String[] args)
{
// Create a trace listener for the event log.
EventLogTraceListener myTraceListener =
new EventLogTraceListener("myEventLogSource");
// Add the event log trace listener to the collection.
Trace.get_Listeners().Add(myTraceListener);
// Write output to the event log.
Trace.WriteLine("Test output");
} //main
System.MarshalByRefObject
System.Diagnostics.TraceListener
System.Diagnostics.EventLogTraceListener
Note: