EventLogEntryCollection.Count 属性
获取事件日志中的项数(EventLogEntry 集合中的元素)。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
Public ReadOnly Property Count As Integer
用法
Dim instance As EventLogEntryCollection
Dim value As Integer
value = instance.Count
public int Count { get; }
public:
virtual property int Count {
int get () sealed;
}
/** @property */
public final int get_Count ()
public final function get Count () : int
属性值
当前在事件日志中的项数。
备注
EventLogEntryCollection 表示日志中所有项的动态列表。因此,Count 在您创建的 EventLogEntryCollection 实例的生存期内可以更改。通常最好直接使用 Count 属性,而不用将其值分配给变量。
示例
' 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
// 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 = 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.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
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
EventLogEntryCollection 类
EventLogEntryCollection 成员
System.Diagnostics 命名空间
EventLog.Entries 属性