Export (0) Print
Expand All

EventLogEntryCollection.Item Property

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

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

public virtual EventLogEntry this [
	int index
] { get; }
/** @property */
public EventLogEntry get_Item (int index)

JScript supports the use of indexed properties, but not the declaration of new ones.

Parameters

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.

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.

// 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);
}

// Create a new EventLog object.
EventLog myEventLog1 = new EventLog();

myEventLog1.set_Log(myLogName);

// Obtain the Log Entries of the Event Log
EventLogEntryCollection myEventLogEntryCollection = 
    myEventLog1.get_Entries();

Console.WriteLine("The number of entries in 'MyNewLog' = " 
    + myEventLogEntryCollection.get_Count());

// Display the 'Message' property of EventLogEntry.
for (int i = 0; i < myEventLogEntryCollection.get_Count(); i++) {
    Console.WriteLine("The Message of the EventLog is :" 
        + myEventLogEntryCollection.get_Item(i).get_Message());
}

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft