EventLogEntry Class
TOC
Collapse the table of content
Expand the table of content

EventLogEntry Class

 

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

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

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Diagnostics.EventLogEntry

[SerializableAttribute]
public sealed class EventLogEntry : Component, ISerializable

NameDescription
System_CAPS_pubpropertyCategory

Gets the text associated with the CategoryNumber property for this entry.

System_CAPS_pubpropertyCategoryNumber

Gets the category number of the event log entry.

System_CAPS_pubpropertyContainer

Gets the IContainer that contains the Component.(Inherited from Component.)

System_CAPS_pubpropertyData

Gets the binary data associated with the entry.

System_CAPS_pubpropertyEntryType

Gets the event type of this entry.

System_CAPS_pubpropertyEventID

Obsolete.Gets the application-specific event identifier for the current event entry.

System_CAPS_pubpropertyIndex

Gets the index of this entry in the event log.

System_CAPS_pubpropertyInstanceId

Gets the resource identifier that designates the message text of the event entry.

System_CAPS_pubpropertyMachineName

Gets the name of the computer on which this entry was generated.

System_CAPS_pubpropertyMessage

Gets the localized message associated with this event entry.

System_CAPS_pubpropertyReplacementStrings

Gets the replacement strings associated with the event log entry.

System_CAPS_pubpropertySite

Gets or sets the ISite of the Component.(Inherited from Component.)

System_CAPS_pubpropertySource

Gets the name of the application that generated this event.

System_CAPS_pubpropertyTimeGenerated

Gets the local time at which this event was generated.

System_CAPS_pubpropertyTimeWritten

Gets the local time at which this event was written to the log.

System_CAPS_pubpropertyUserName

Gets the name of the user who is responsible for this event.

NameDescription
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 Component.(Inherited from Component.)

System_CAPS_pubmethodEquals(EventLogEntry)

Performs a comparison between two event log entries.

System_CAPS_pubmethodEquals(Object)

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

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_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 containing the name of the Component, if any. This method should not be overridden.(Inherited from Component.)

NameDescription
System_CAPS_pubeventDisposed

Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Populates a SerializationInfo with the data needed to serialize the target object.

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.

System_CAPS_importantImportant

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.

Win98WinMe

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;
using System.Diagnostics;
   class MyEventlogClass
   {
      public static void Main()
      {
         String myEventType=null;
         // Associate the instance of 'EventLog' with local System Log.
         EventLog myEventLog = new 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.ToString().Equals(myEventType))
               {
                  // Display Source of the event.
                  Console.WriteLine(myLogEntry.Source
                     +" was the source of last event of type "
                     +myLogEntry.EntryType);
                  return;
               }
            }

         }
   }

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft