Breyta

Deila með


EventLogTraceListener Class

Definition

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

public ref class EventLogTraceListener sealed : System::Diagnostics::TraceListener
public sealed class EventLogTraceListener : System.Diagnostics.TraceListener
type EventLogTraceListener = class
    inherit TraceListener
Public NotInheritable Class EventLogTraceListener
Inherits TraceListener
Inheritance
EventLogTraceListener

Examples

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.

int main()
{
   #if defined(TRACE)
   
   // Create a trace listener for the event log.
   EventLogTraceListener^ myTraceListener = 
      gcnew 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" );
   
   #endif
}
// 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");
Overloads Public Shared Sub Main(args() As String)
   
    ' Create a trace listener for the event log.
    Dim myTraceListener As 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")
End Sub

Remarks

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, for a .NET Framework app, specify it in the application configuration file.

To add an EventLogTraceListener using a .NET Framework application configuration file, edit the file that corresponds to the name of your application. 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>  

Note

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.

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.

Constructors

EventLogTraceListener()

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

EventLogTraceListener(EventLog)

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

EventLogTraceListener(String)

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

Properties

Attributes

Gets the custom trace listener attributes defined in the application configuration file.

(Inherited from TraceListener)
EventLog

Gets or sets the event log to write to.

Filter

Gets or sets the trace filter for the trace listener.

(Inherited from TraceListener)
IndentLevel

Gets or sets the indent level.

(Inherited from TraceListener)
IndentSize

Gets or sets the number of spaces in an indent.

(Inherited from TraceListener)
IsThreadSafe

Gets a value indicating whether the trace listener is thread safe.

(Inherited from TraceListener)
Name

Gets or sets the name of this EventLogTraceListener.

NeedIndent

Gets or sets a value indicating whether to indent the output.

(Inherited from TraceListener)
TraceOutputOptions

Gets or sets the trace output options.

(Inherited from TraceListener)

Methods

Close()

Closes the event log so that it no longer receives tracing or debugging output.

CreateObjRef(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)
Dispose()

Releases all resources used by the TraceListener.

(Inherited from TraceListener)
Dispose(Boolean)

Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources.

(Inherited from TraceListener)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Fail(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)
Fail(String)

Emits an error message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Flush()

When overridden in a derived class, flushes the output buffer.

(Inherited from TraceListener)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSupportedAttributes()

Gets the custom attributes supported by the trace listener.

(Inherited from TraceListener)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
TraceData(TraceEventCache, String, TraceEventType, Int32, Object)

Writes trace information, a data object, and event information to the event log.

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

Writes trace information, a data object and event information to the listener specific output.

(Inherited from TraceListener)
TraceData(TraceEventCache, String, TraceEventType, Int32, Object[])

Writes trace information, an array of data objects, and event information to the event log.

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

Writes trace information, an array of data objects and event information to the listener specific output.

(Inherited from TraceListener)
TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[])

Writes trace information, a formatted array of objects, and event information to the event log.

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

Writes trace information, a formatted array of objects and event information to the listener specific output.

(Inherited from TraceListener)
TraceEvent(TraceEventCache, String, TraceEventType, Int32, String)

Writes trace information, a message, and event information to the event log.

TraceEvent(TraceEventCache, String, TraceEventType, Int32, String)

Writes trace information, a message, and event information to the listener specific output.

(Inherited from TraceListener)
TraceEvent(TraceEventCache, String, TraceEventType, Int32)

Writes trace and event information to the listener specific output.

(Inherited from TraceListener)
TraceTransfer(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)
Write(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)
Write(Object)

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

(Inherited from TraceListener)
Write(String, String)

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

(Inherited from TraceListener)
Write(String)

Writes a message to the event log for this instance.

WriteIndent()

Writes the indent to the listener you create when you implement this class, and resets the NeedIndent property to false.

(Inherited from TraceListener)
WriteLine(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)
WriteLine(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)
WriteLine(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)
WriteLine(String)

Writes a message to the event log for this instance.

Applies to

Thread Safety

This type is thread safe.

See also