EventLogEntryCollection.Item[Int32] Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém uma entrada no registo de eventos, baseada num índice que começa em 0 (zero).
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
O índice baseado em zero associado à entrada do registo de eventos.
Valor de Propriedade
A entrada do registo de eventos no local especificado pelo index parâmetro.
Exemplos
O exemplo seguinte demonstra como mostrar a informação dos itens num 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
Observações
EventLogEntry Os objetos são indexados pelo sistema de registo de eventos de acordo com a ordem cronológica em que chegaram ao registo de eventos. Use a Item[] propriedade para selecionar uma entrada específica no registo de eventos cujo índice na coleção seja conhecido.
Iterar pela EventLogEntryCollection instância passa por cada EventLogEntry objeto sequencialmente. A coleção é dinâmica e o número de entradas pode não ser imutável quando entra no ciclo. Por isso, deve usar um for each...next loop em vez de um for(int i=0; i<count, i++) loop para passar pelas entradas associadas à EventLogEntryCollection instância e examinar todo o conjunto de entradas.
Como novas entradas são adicionadas à lista existente, percorrer a coleção permite aceder às entradas criadas depois de ter criado originalmente o EventLogEntryCollection.