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 = 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[] インデックスがわかっている特定のイベント ログ エントリを選択するには、 プロパティを使用します。

インスタンスを反復処理すると、 EventLogEntryCollectionEventLogEntry オブジェクトが順番にステップ実行されます。 コレクションは動的であり、ループに入るときにエントリの数が変更できない場合があります。 したがって、ループではなくfor(int i=0; i<count, i++)ループをfor each...next使用して、インスタンスに関連付EventLogEntryCollectionけられているエントリをステップ実行して、エントリのセット全体を調べる必要があります。

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

適用対象

こちらもご覧ください