Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 sealed class EventLogEntry : Component, ISerializable
/** @attribute SerializableAttribute() */ 
public final class EventLogEntry extends Component implements ISerializable
SerializableAttribute 
public final class EventLogEntry extends Component implements ISerializable
Not applicable.

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.

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;
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;
               }
            }

         }
   }

import System.*;
import System.Diagnostics.*;

class MyEventlogClass
{
    public static void main(String[] args)
    {
        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.get_Entries();
        int myCount = myLogEntryCollection.get_Count();

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

            // Select the entry having desired EventType.
            if (myLogEntry.get_EntryType().ToString().Equals(myEventType)) {
                // Display Source of the event.
                Console.WriteLine(myLogEntry.get_Source() 
                    + " was the source of last event of type " 
                    + myLogEntry.get_EntryType());
                return;
            }
        }
    } //main
} //MyEventlogClass 

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

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

Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

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

Community Additions

Show:
© 2014 Microsoft