EventLogEntryCollection.Item[Int32] Propiedad

Definición

Obtiene una entrada en el registro de eventos, basada en un índice que comienza en 0 (cero).

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

Parámetros

index
Int32

Índice de base cero asociado a la entrada del registro de eventos.

Valor de propiedad

Entrada del registro de eventos en la ubicación especificada por el index parámetro .

Ejemplos

En el ejemplo siguiente se muestra cómo mostrar información de los elementos de un EventLogEntryCollection objeto .

// 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

Comentarios

EventLogEntry El sistema de registro de eventos indexa los objetos según el orden cronológico en el que llegaron al registro de eventos. Use la Item[] propiedad para seleccionar una entrada de registro de eventos específica cuyo índice en la colección se conoce.

Recorrer en iteración los pasos de la EventLogEntryCollection instancia a través de cada EventLogEntry objeto secuencialmente. La colección es dinámica y es posible que el número de entradas no sea inmutable al entrar en el bucle. Por lo tanto, debe usar un for each...next bucle en lugar de un for(int i=0; i<count, i++) bucle para recorrer paso a paso las entradas asociadas a la EventLogEntryCollection instancia para examinar todo el conjunto de entradas.

Dado que las nuevas entradas se anexan a la lista existente, recorrer la colección le permite acceder a las entradas que se crearon después de crear originalmente .EventLogEntryCollection

Se aplica a

Consulte también