EventLogEntryCollection.Item[Int32] 属性

定义

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

public:
 virtual property System::Diagnostics::EventLogEntry ^ default[int] { System::Diagnostics::EventLogEntry ^ get(int index); };
public virtual System.Diagnostics.EventLogEntry this[int index] { get; }
member this.Item(int) : System.Diagnostics.EventLogEntry
Default Public Overridable ReadOnly Property Item(index As Integer) As EventLogEntry

参数

index
Int32

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

属性值

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

示例

以下示例演示如何显示 对象中 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

注解

EventLogEntry 事件日志系统根据对象到达事件日志的时间顺序对对象编制索引。 Item[]使用 属性选择集合中其索引已知的特定事件日志条目。

循环访问实例按 EventLogEntryCollection 顺序遍历每个 EventLogEntry 对象。 集合是动态的,进入循环时,条目数可能不可变。 因此,应使用 for each...next 循环而不是 for(int i=0; i<count, i++) 循环来逐行执行与 EventLogEntryCollection 实例关联的条目,以检查整个条目集。

由于新条目将追加到现有列表,因此单步执行集合使你能够访问最初创建 后创建的 EventLogEntryCollection条目。

适用于

另请参阅