EventLogEntryCollection.Item Property (Int32)


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

Gets an entry in the event log, based on an index that starts at 0 (zero).

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

Public Overridable ReadOnly Property Item (
	index As Integer
) As EventLogEntry


Type: System.Int32

The zero-based index that is associated with the event log entry.

Property Value

Type: System.Diagnostics.EventLogEntry

The event log entry at the location that is specified by the index parameter.

EventLogEntry objects are indexed by the event log system according to the chronological order in which they arrived in the event log. Use the Item property to select a specific event log entry whose index in the collection is known.

Iterating through the EventLogEntryCollection instance steps through each EventLogEntry object sequentially. The collection is dynamic and the number of entries may not be immutable when you enter the loop. Therefore, you should use a for each...next loop instead of a for(int i=0; i<count, i++) loop to step through entries that are associated with the EventLogEntryCollection instance to examine the entire set of entries.

Because new entries are appended to the existing list, stepping through the collection enables you to access the entries that were created after you originally created the EventLogEntryCollection.

The following example demonstrates how to display information for the items in an EventLogEntryCollection object.

' Create a new EventLog object.
Dim myEventLog1 As New EventLog()
myEventLog1.Log = myLogName
' Obtain the Log Entries of the Event Log
Dim myEventLogEntryCollection As EventLogEntryCollection = myEventLog1.Entries
Console.WriteLine("The number of entries in 'MyNewLog' = " + _
' Display the 'Message' property of EventLogEntry.
Dim i As Integer
For i = 0 To myEventLogEntryCollection.Count - 1
   Console.WriteLine("The Message of the EventLog is :" + _
Next i

.NET Framework
Available since 1.1
Return to top