EventLogEntryCollection.Count 属性

定义

获取事件日志中的项数(即 EventLogEntry 集合中的元素个数)。

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

属性值

当前在事件日志中的项数。

实现

示例

以下示例演示如何使用 Count 属性循环访问 EventLogEntryCollection 对象。

// 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 日志中所有条目的动态列表。 因此,属性 Count 可以在创建的实例的 EventLogEntryCollection 生存期内更改。 通常,最好直接使用 属性, Count 而不是将其值赋给变量。

适用于

另请参阅