EventLogEntryCollection.Item[Int32] Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene una entrada del registro de eventos, en función de un índice que empieza por 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 parámetro index.
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 = 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
Comentarios
EventLogEntry El sistema de registro de eventos indexa los objetos según el orden cronológico en el que llegaron en el registro de eventos. Use la Item[] propiedad para seleccionar una entrada de registro de eventos específica cuyo índice de 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, la ejecución paso a paso por la colección permite tener acceso a las entradas que se crearon después de crear originalmente .EventLogEntryCollection