This documentation is archived and is not being maintained.

EventLogEntry.EntryType Property

Gets the event type of this entry.

[Visual Basic]
Public ReadOnly Property EntryType As EventLogEntryType
[C#]
public EventLogEntryType EntryType {get;}
[C++]
public: __property EventLogEntryType get_EntryType();
[JScript]
public function get EntryType() : EventLogEntryType;

Property Value

The EventLogEntryType that indicates the event type associated with the entry in the event log. This is usually used to indicate the severity of the event log entry.

Remarks

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, representing the severity of the entry, to display in the list view of the event log.

Example

[Visual Basic] 
Imports System
Imports System.Diagnostics

Class MyEventlogClass

   Public Shared Sub Main()
      Dim myEventType As String = Nothing
      ' Associate the instance of 'EventLog' with local System Log.
      Dim myEventLog As New EventLog("System", ".")
      Console.WriteLine("1:Error")
      Console.WriteLine("2:Information")
      Console.WriteLine("3:Warning")
      Console.WriteLine("Select the Event Type")
      Dim myOption As Integer = Convert.ToInt32(Console.ReadLine())
      Select Case myOption
         Case 1
            myEventType = "Error"
         Case 2
            myEventType = "Information"
         Case 3
            myEventType = "Warning"
         Case Else
      End Select

      Dim myLogEntryCollection As EventLogEntryCollection = myEventLog.Entries
      Dim myCount As Integer = myLogEntryCollection.Count
      ' Iterate through all 'EventLogEntry' instances in 'EventLog'.
      Dim i As Integer
      For i = myCount - 1 To -1 Step -1
         Dim myLogEntry As EventLogEntry = myLogEntryCollection(i)
         ' Select the entry having desired EventType.
         If myLogEntry.EntryType.ToString().Equals(myEventType) Then
            ' Display Source of the event.
            Console.WriteLine(myLogEntry.Source + " was the source of last "& _
                             "event of type " & myLogEntry.EntryType.ToString())
            Return
         End If
      Next i

   End Sub 'Main
End Class 'MyEventlogClass

[C#] 
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;
               }
            }

         }
   }

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

void main() {
    String* myEventType = 0;
    // Associate the instance of 'EventLog' with local System Log.
    EventLog* myEventLog = new EventLog(S"System", S".");
    Console::WriteLine(S"1:Error");
    Console::WriteLine(S"2:Information");
    Console::WriteLine(S"3:Warning");
    Console::WriteLine(S"Select the Event Type");
    int myOption=Convert::ToInt32(Console::ReadLine());
    switch (myOption) {
        case 1:  myEventType=S"Error";
            break;
        case 2:  myEventType=S"Information";
            break;
        case 3:  myEventType=S"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->Item[i];
        // Select the entry having desired EventType.
        if (__box(myLogEntry->EntryType)->Equals(myEventType)) {
            // Display Source of the event.
            Console::WriteLine(S"{0} was the source of last event of type {1}", 
                myLogEntry->Source, __box(myLogEntry->EntryType));
            return;
        }
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

EventLogEntry Class | EventLogEntry Members | System.Diagnostics Namespace | CategoryNumber | EventLogEntryType

Show: