Export (0) Print
Expand All

EventLogEntryCollection.Count Property

Gets the number of entries in the event log (that is, the number of elements in the EventLogEntry collection).

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

public int Count { get; }
/** @property */
public final int get_Count ()

public final function get Count () : int

Not applicable.

Property Value

The number of entries currently in the event log.

An EventLogEntryCollection represents a dynamic list of all the entries in a log. Therefore, the Count property can change during the lifetime of the EventLogEntryCollection instance that you create. It is usually best to work with the Count property directly instead of assigning its value to a variable.

The following example demonstrates how to use the Count property to iterate through an EventLogEntryCollection object.

// 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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft