EventLogEntry.EntryType Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the event type of this entry.

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

public EventLogEntryType EntryType { get; }

Property Value

Type: System.Diagnostics.EventLogEntryType

The event type that is associated with the entry in the event log.

All event types have well-defined common data and can optionally include event-specific data. Each event is of a single type, which the application indicates when it reports the event. The Event Viewer uses the event type to determine which icon to display in the list view of the event log.

The following code example demonstrates the use of the EntryType property. In this example, a switch statement uses console input to search for event log entries for the specified EntryType. 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("Select the Event Type");
         int myOption=Convert.ToInt32(Console.ReadLine());
            case 1:  myEventType="Error";
            case 2:  myEventType="Information";
            case 3:  myEventType="Warning";
            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.
                  // Display Source of the event.
                     +" was the source of last event of type "


.NET Framework
Available since 1.1
Return to top