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.