EventLogEntryCollection.Item[Int32] Właściwość

Definicja

Pobiera wpis w dzienniku zdarzeń na podstawie indeksu rozpoczynającego się od 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

Parametry

index
Int32

Indeks oparty na zerze skojarzony z wpisem dziennika zdarzeń.

Wartość właściwości

Wpis dziennika zdarzeń w lokalizacji określonej przez index parametr .

Przykłady

W poniższym przykładzie pokazano, jak wyświetlać informacje o elementach w EventLogEntryCollection obiekcie.

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

Uwagi

EventLogEntry obiekty są indeksowane przez system dziennika zdarzeń zgodnie z kolejnością chronologiczną, w której dotarły do dziennika zdarzeń. Item[] Użyj właściwości , aby wybrać określony wpis dziennika zdarzeń, którego indeks w kolekcji jest znany.

Iterowanie przez EventLogEntryCollection wystąpienie kroków po poszczególnych EventLogEntry obiektach sekwencyjnie. Kolekcja jest dynamiczna, a liczba wpisów może nie być niezmienna podczas wprowadzania pętli. W związku z tym należy użyć for each...next pętli zamiast for(int i=0; i<count, i++) pętli, aby przejść przez wpisy skojarzone z EventLogEntryCollection wystąpieniem w celu zbadania całego zestawu wpisów.

Ponieważ nowe wpisy są dołączane do istniejącej listy, przechodzenie przez tę kolekcję umożliwia dostęp do wpisów utworzonych po utworzeniu EventLogEntryCollectionelementu .

Dotyczy

Zobacz też