Partilhar via


EventLogEntryCollection.Count Propriedade

Definição

Obtém o número de entradas no log de eventos (ou seja, o número de elementos na EventLogEntry coleção).

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

Valor da propriedade

O número de entradas atualmente no log de eventos.

Implementações

Exemplos

O exemplo a seguir demonstra como usar a Count propriedade para iterar por meio de 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

Representa EventLogEntryCollection uma lista dinâmica de todas as entradas em um log. Portanto, a Count propriedade pode ser alterada durante o tempo de vida da EventLogEntryCollection instância que você cria. Geralmente, é melhor trabalhar com a Count propriedade diretamente em vez de atribuir seu valor a uma variável.

Aplica-se a

Confira também