EventLogEntry Class

Encapsulates a single record in the event log. This class cannot be inherited.

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

[SerializableAttribute]
public ref class EventLogEntry sealed : public Component, 
	ISerializable

The EventLogEntry type exposes the following members.

  NameDescription
Public propertyCategoryGets the text associated with the CategoryNumber property for this entry.
Public propertyCategoryNumberGets the category number of the event log entry.
Public propertyContainerGets the IContainer that contains the Component. (Inherited from Component.)
Public propertyDataGets the binary data associated with the entry.
Public propertyEntryTypeGets the event type of this entry.
Public propertyEventID Obsolete. Gets the application-specific event identifier for the current event entry.
Public propertyIndexGets the index of this entry in the event log.
Public propertyInstanceIdGets the resource identifier that designates the message text of the event entry.
Public propertyMachineNameGets the name of the computer on which this entry was generated.
Public propertyMessageGets the localized message associated with this event entry.
Public propertyReplacementStringsGets the replacement strings associated with the event log entry.
Public propertySiteGets or sets the ISite of the Component. (Inherited from Component.)
Public propertySourceGets the name of the application that generated this event.
Public propertyTimeGeneratedGets the local time at which this event was generated.
Public propertyTimeWrittenGets the local time at which this event was written to the log.
Public propertyUserNameGets the name of the user who is responsible for this event.
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDispose()Releases all resources used by the Component. (Inherited from Component.)
Public methodEquals(EventLogEntry)Performs a comparison between two event log entries.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Top

  NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Top

  NameDescription
Explicit interface implemetationPrivate methodISerializable::GetObjectDataInfrastructure. Populates a SerializationInfo with the data needed to serialize the target object.
Top

You usually will not create instances of EventLogEntry directly when working with the EventLog class. The Entries member of the EventLog class contains a collection of EventLogEntry instances, which you iterate over when reading by using the EventLogEntryCollection::Item class index member.

Important noteImportant

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

Windows 98, Windows Millennium Edition Platform Note: Event logs are not supported on Windows 98 or Windows Millennium.

The following code example demonstrates the use of the EventLogEntry class. In this example, a switch statement uses console input to search for event log entries for the specified event type. If a match is found, log entry source information is displayed at the console.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

int main()
{
   String^ myEventType = nullptr;

   // Associate the instance of 'EventLog' with local System Log.
   EventLog^ myEventLog = gcnew EventLog( "System","." );
   Console::WriteLine( "1:Error" );
   Console::WriteLine( "2:Information" );
   Console::WriteLine( "3:Warning" );
   Console::WriteLine( "Select the Event Type" );
   int myOption = Convert::ToInt32( Console::ReadLine() );
   switch ( myOption )
   {
      case 1:
         myEventType = "Error";
         break;

      case 2:
         myEventType = "Information";
         break;

      case 3:
         myEventType = "Warning";
         break;

      default:
         break;
   }
   EventLogEntryCollection^ myLogEntryCollection = myEventLog->Entries;
   int myCount = myLogEntryCollection->Count;

   // Iterate through all 'EventLogEntry' instances in 'EventLog'. 
   for ( int i = myCount - 1; i > 0; i-- )
   {
      EventLogEntry^ myLogEntry = myLogEntryCollection[ i ];

      // Select the entry having desired EventType. 
      if ( myLogEntry->EntryType.Equals( myEventType ) )
      {
         // Display Source of the event.
         Console::WriteLine( "{0} was the source of last event of type {1}", myLogEntry->Source, myLogEntry->EntryType );
         return 0;
      }
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft