Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

EventLogEntryCollection.Item Property

Gets an entry in the event log, based on an index starting at 0.

[C#] In C#, this property is the indexer for the EventLogEntryCollection class.

[Visual Basic]
Public Overridable Default ReadOnly Property Item( _
   ByVal index As Integer _
) As EventLogEntry
[C#]
public virtual EventLogEntry this[
 int index
] {get;}
[C++]
public: __property virtual EventLogEntry* get_Item(
 int index
);
[JScript]
returnValue = EventLogEntryCollectionObject.Item(index);
-or-
returnValue = EventLogEntryCollectionObject(index);

[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.

Arguments [JScript]

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

Parameters [Visual Basic, C#, C++]

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

Property Value

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

Remarks

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

Iterating through the EventLogEntryCollection instance steps through each of these EventLogEntry objects sequentially. Use a for each...next loop rather than a for(int i=0; i<count, i++) loop to step through entries associated with the EventLogEntryCollection instance to examine the entire set of entries, because the collection is dynamic and the number of entries may not be immutable when you enter the loop.

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

Example

[Visual Basic] 
' 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' = " + _
                           myEventLogEntryCollection.Count.ToString())
' 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 :" + _
                  myEventLogEntryCollection(i).Message)
Next i

[C#] 
// Create a new EventLog object.
EventLog myEventLog1 = new EventLog();
myEventLog1.Log = myLogName;
// Obtain the Log Entries of the Event Log
EventLogEntryCollection myEventLogEntryCollection=myEventLog1.Entries;
Console.WriteLine("The number of entries in 'MyNewLog' = "+
                        myEventLogEntryCollection.Count);
// Display the 'Message' property of EventLogEntry.
for(int i=0;i<myEventLogEntryCollection.Count;i++)
{
   Console.WriteLine("The Message of the EventLog is :"+
                           myEventLogEntryCollection[i].Message);
}

[C++] 
// Create a new EventLog object.
EventLog* myEventLog1 = new EventLog();
myEventLog1->Log = myLogName;
// Obtain the Log Entries of the Event Log
EventLogEntryCollection* myEventLogEntryCollection=myEventLog1->Entries;
Console::WriteLine(S"The number of entries in 'MyNewLog' = {0}", __box(myEventLogEntryCollection->Count));
// Display the 'Message' property of EventLogEntry.
for (int i=0; i<myEventLogEntryCollection->Count; i++) {
    Console::WriteLine(S"The Message of the EventLog is : {0}", myEventLogEntryCollection->Item[i]->Message);
}

[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

EventLogEntryCollection Class | EventLogEntryCollection Members | System.Diagnostics Namespace | Count

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.