共用方式為


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之後所建立的專案。

適用於

另請參閱