0 から始まるインデックスに基づいて、イベント ログのエントリを取得します。
[C#] C# では、このプロパティは EventLogEntryCollection クラスのインデクサになります。
Public Overridable Default ReadOnly Property Item( _
ByVal index As Integer _) As EventLogEntry
[C#]
public virtual EventLogEntry this[intindex] {get;}
[C++]
public: __property virtual EventLogEntry* get_Item(intindex);
[JScript]
returnValue = EventLogEntryCollectionObject.Item(index);またはreturnValue = EventLogEntryCollectionObject(index);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- index
イベント ログ エントリに関連付けられた、0 から始まるインデックス。
パラメータ [Visual Basic, C#, C++]
- index
イベント ログ エントリに関連付けられた、0 から始まるインデックス。
プロパティ値
index パラメータで指定した位置にあるイベント ログ エントリ。
解説
EventLogEntry オブジェクトには、オブジェクトがイベント ログに到達した順に、イベント ログ システムによってインデックスが割り当てられます。このプロパティを使用して、コレクション内のインデックスを認識している特定のイベント ログ エントリを選択します。
EventLogEntryCollection インスタンスを反復処理して、各 EventLogEntry オブジェクトに順にアクセスします。 EventLogEntryCollection インスタンスに関連付けられたエントリに順にアクセスして、エントリのセット全体をチェックするには、 for(int i=0; i<count, i++)
ループではなく for each...next
ループを使用します。これは、コレクションが動的であり、ループ時にエントリ数が変化する可能性があるためです。
新しいエントリは既存のリストの末尾に追加されるため、コレクションを順に処理していけば、最初に EventLogEntryCollection を作成した後で作成されたエントリにもアクセスできます。
使用例
' 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
[C#]
// 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);
}
[C++]
// 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(S"The number of entries in 'MyNewLog' = {0}", __box(myEventLogEntryCollection->Count));
// Display the 'Message' property of EventLogEntry.
for (int i=0; i<myEventLogEntryCollection->Count; i++) {
Console::WriteLine(S"The Message of the EventLog is : {0}", myEventLogEntryCollection->Item[i]->Message);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
EventLogEntryCollection クラス | EventLogEntryCollection メンバ | System.Diagnostics 名前空間 | Count