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

イベント ログ エントリに関連付けられている 0 から始まるインデックス。

プロパティ値

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(int i=0; i<count, i++) ループではなくfor each...next ループを使用して、EventLogEntryCollection インスタンスに関連付けられているエントリをステップ実行して、エントリのセット全体を調べる必要があります。

新しいエントリは既存のリストに追加されるため、コレクションをステップ実行すると、最初に EventLogEntryCollectionを作成した後に作成されたエントリにアクセスできます。

適用対象

こちらもご覧ください