Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

EventLogTraceListener Class

Provides a simple listener that directs tracing or debugging output to an EventLog.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public sealed class EventLogTraceListener : TraceListener
public final class EventLogTraceListener extends TraceListener
public final class EventLogTraceListener extends TraceListener
Not applicable.

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.

NoteNote:

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.

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.Object
   System.MarshalByRefObject
     System.Diagnostics.TraceListener
      System.Diagnostics.EventLogTraceListener

This type is thread safe.

Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

Show: