Export (0) Print
Expand All

EventLogEntryCollection.Count Property

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

[Visual Basic]
Public Overridable ReadOnly Property Count As Integer  Implements _
   ICollection.Count
[C#]
public virtual int Count {get;}
[C++]
public: __property virtual int get_Count();
[JScript]
public function get Count() : int;

Property Value

The number of entries currently in the event log.

Implements

ICollection.Count

Remarks

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

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 | Entries

Show:
© 2014 Microsoft