EventLogEntryCollection.Item[Int32] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
根据从 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 = 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后创建的条目。