Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

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
NoteNote

The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

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 outputs to an event log. First, the code creates an event log called myEventLog. Then, a new EventLogTraceListener is created that uses myEventLog. Next, myTraceListener is added to the Trace.Listeners collection. Finally, the example outputs a line 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 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.