EventLogEntryCollection.Item[Int32] Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém uma entrada no log de eventos, com base em um í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 de log de eventos.
Valor da propriedade
A entrada do log de eventos no local especificado pelo index parâmetro.
Exemplos
O exemplo a seguir demonstra como exibir informações para os itens em um 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
Comentários
EventLogEntry os objetos são indexados pelo sistema de log de eventos de acordo com a ordem cronológica em que chegaram ao log de eventos. Use a Item[] propriedade para selecionar uma entrada de log de eventos específica cujo índice na coleção é conhecido.
Iterando pelas etapas da EventLogEntryCollection instância por meio de cada EventLogEntry objeto sequencialmente. A coleção é dinâmica e o número de entradas pode não ser imutável quando você insere o loop. Portanto, você deve usar um for each...next loop em vez de um for(int i=0; i<count, i++) loop para percorrer entradas associadas à EventLogEntryCollection instância para examinar todo o conjunto de entradas.
Como novas entradas são acrescentadas à lista existente, percorrer a coleção permite que você acesse as entradas que foram criadas depois que você criou o EventLogEntryCollection.