EventLogEntryCollection.Count 属性

定义

获取事件日志中的项数(即 EventLogEntry 集合中的元素个数)。Gets the number of entries in the event log (that is, the number of elements in the EventLogEntry collection).

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

属性值

Int32

当前在事件日志中的项数。The number of entries currently in the event log.

实现

示例

下面的示例演示如何使用 Count 属性来循环访问 EventLogEntryCollection 对象。The following example demonstrates how to use the Count property to iterate through an EventLogEntryCollection object.

// Create a new EventLog object.
EventLog^ myEventLog1 = gcnew EventLog;
myEventLog1->Log = myLogName;

// Obtain the Log Entries of the Event Log
EventLogEntryCollection^ myEventLogEntryCollection = myEventLog1->Entries;
Console::WriteLine( "The number of entries in 'MyNewLog' = {0}", myEventLogEntryCollection->Count );

// Display the 'Message' property of EventLogEntry.
for ( int i = 0; i < myEventLogEntryCollection->Count; i++ )
{
   Console::WriteLine( "The Message of the EventLog is : {0}", myEventLogEntryCollection[ i ]->Message );
}
// 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.
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

注解

EventLogEntryCollection表示日志中所有条目的动态列表。An EventLogEntryCollection represents a dynamic list of all the entries in a log. 因此,在 Count 创建的实例的生存期内,属性可能会更改 EventLogEntryCollectionTherefore, the Count property can change during the lifetime of the EventLogEntryCollection instance that you create. 通常最好 Count 直接使用属性,而不是将其值分配给变量。It is usually best to work with the Count property directly instead of assigning its value to a variable.

适用于

另请参阅