EventLogEntryCollection.Item 属性

基于从零开始的索引,获取事件日志中的项。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public Overridable ReadOnly Default Property Item ( _
    index As Integer _
) As EventLogEntry
用法
Dim instance As EventLogEntryCollection
Dim index As Integer
Dim value As EventLogEntry

value = instance(index)
public virtual EventLogEntry this [
    int index
] { get; }
public:
virtual property EventLogEntry^ default [int] {
    EventLogEntry^ get (int index);
}
/** @property */
public EventLogEntry get_Item (int index)
JScript 支持使用索引属性,但不支持进行新的声明。

参数

  • index
    从零开始的与事件日志项关联的索引。

属性值

位于 index 参数所指定的位置的事件日志项。

备注

按照对象到达事件日志的时间顺序,由事件日志系统创建 EventLogEntry 对象的索引。使用此属性选择特定的事件日志项,该事件日志项的索引在集合中为已知。

循环访问 EventLogEntryCollection 实例将按顺序逐句通过这些 EventLogEntry 对象中的每个对象。使用 for each...next 循环(而非 for(int i=0; i<count, i++) 循环)逐句通过与 EventLogEntryCollection 实例关联的项来检查所有项,因为在您进入循环时,该集合是动态的,项数可能不固定。

由于新项被追加到现有列表的末尾,因此逐句通过该集合使您能够访问在最初创建 EventLogEntryCollection 之后创建的项。

示例

' 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 命名空间
EventLogEntryCollection.Count 属性