This documentation is archived and is not being maintained.

EventLogEntry Class

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

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

'Declaration
<SerializableAttribute> _
Public NotInheritable Class EventLogEntry _
	Inherits Component _
	Implements ISerializable
'Usage
Dim instance As EventLogEntry

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.

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

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: