TechNet
Export (0) Print
Expand All

EventLogTraceListener Class

 

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

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

System.Object
  System.MarshalByRefObject
    System.Diagnostics.TraceListener
      System.Diagnostics.EventLogTraceListener

[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
public sealed class EventLogTraceListener : TraceListener

NameDescription
System_CAPS_pubmethodEventLogTraceListener()

Initializes a new instance of the EventLogTraceListener class without a trace listener.

System_CAPS_pubmethodEventLogTraceListener(EventLog)

Initializes a new instance of the EventLogTraceListener class using the specified event log.

System_CAPS_pubmethodEventLogTraceListener(String)

Initializes a new instance of the EventLogTraceListener class using the specified source.

NameDescription
System_CAPS_pubpropertyAttributes

Gets the custom trace listener attributes defined in the application configuration file.(Inherited from TraceListener.)

System_CAPS_pubpropertyEventLog

Gets or sets the event log to write to.

System_CAPS_pubpropertyFilter

Gets and sets the trace filter for the trace listener.(Inherited from TraceListener.)

System_CAPS_pubpropertyIndentLevel

Gets or sets the indent level.(Inherited from TraceListener.)

System_CAPS_pubpropertyIndentSize

Gets or sets the number of spaces in an indent.(Inherited from TraceListener.)

System_CAPS_pubpropertyIsThreadSafe

Gets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener.)

System_CAPS_pubpropertyName

Gets or sets the name of this EventLogTraceListener.(Overrides TraceListener.Name.)

System_CAPS_pubpropertyTraceOutputOptions

Gets or sets the trace output options.(Inherited from TraceListener.)

NameDescription
System_CAPS_pubmethodClose()

Closes the event log so that it no longer receives tracing or debugging output.(Overrides TraceListener.Close().)

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by the TraceListener.(Inherited from TraceListener.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodFail(String)

Emits an error message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethodFail(String, String)

Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethodFlush()

When overridden in a derived class, flushes the output buffer.(Inherited from TraceListener.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodGetSupportedAttributes()

Gets the custom attributes supported by the trace listener.(Inherited from TraceListener.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodTraceData(TraceEventCache, String, TraceEventType, Int32, Object)

Writes trace information, a data object, and event information to the event log.(Overrides TraceListener.TraceData(TraceEventCache, String, TraceEventType, Int32, Object).)

System_CAPS_pubmethodTraceData(TraceEventCache, String, TraceEventType, Int32, Object[])

Writes trace information, an array of data objects, and event information to the event log.(Overrides TraceListener.TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]).)

System_CAPS_pubmethodTraceEvent(TraceEventCache, String, TraceEventType, Int32)

Writes trace and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethodTraceEvent(TraceEventCache, String, TraceEventType, Int32, String)

Writes trace information, a message, and event information to the event log.(Overrides TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String).)

System_CAPS_pubmethodTraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[])

Writes trace information, a formatted array of objects, and event information to the event log.(Overrides TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]).)

System_CAPS_pubmethodTraceTransfer(TraceEventCache, String, Int32, String, Guid)

Writes trace information, a message, a related activity identity and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethodWrite(Object)

Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethodWrite(Object, String)

Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethodWrite(String)

Writes a message to the event log for this instance.(Overrides TraceListener.Write(String).)

System_CAPS_pubmethodWrite(String, String)

Writes a category name and a message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethodWriteLine(Object)

Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.)

System_CAPS_pubmethodWriteLine(Object, String)

Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.)

System_CAPS_pubmethodWriteLine(String)

Writes a message to the event log for this instance.(Overrides TraceListener.WriteLine(String).)

System_CAPS_pubmethodWriteLine(String, String)

Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.)

An instance of this EventLogTraceListener can be added to the Debug.Listeners, Trace.Listeners, or TraceSource.Listeners collections to send output from tracing or debugging to an EventLog. You can add the instance in your code or specify it in the application configuration file. To add an EventLogTraceListener using an application configuration file, edit the file that corresponds to the name of your application or the app.config file in a Visual Studio 2005 project. In this file, insert an element for a System.Diagnostics.EventLogTraceListener type.

The following example adds a EventLogTraceListener object named myListener to the Trace.Listeners collection. The initializeData parameter specifies the name of the event log source that is to be passed to the EventLogTraceListener(String) constructor.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener"
          type="System.Diagnostics.EventLogTraceListener"
          initializeData="TraceListenerLog" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

For more information about how to add trace listeners in the application configuration file, see or .

System_CAPS_noteNote

If the Source for the event log that is associated with the EventLogTraceListener instance does not exist, a new event source is created. To create an event source in Windows Vista, Windows XP Professional, or Windows Server 2003, you must have administrative privileges.

The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. In Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown.

In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

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.

System_CAPS_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");
 }

.NET Framework
Available since 1.1

This type is thread safe.

Return to top
Show:
© 2016 Microsoft