EventLogEntryCollection Klasa

Definicja

Definiuje rozmiar i moduły wyliczania dla kolekcji EventLogEntry wystąpień.

C#
public class EventLogEntryCollection : System.Collections.ICollection
Dziedziczenie
EventLogEntryCollection
Implementuje

Przykłady

W poniższym przykładzie pokazano, jak uzyskać informacje dziennika zdarzeń z EventLogEntryCollection obiektu.

C#
using System;
using System.Collections;
using System.Diagnostics;

class EventLogEntryCollection_Item
{
    public static void Main()
    {
        try
        {
            string myLogName = "MyNewLog";
            // Check if the source exists.
            if (!EventLog.SourceExists("MySource"))
            {
                // Create the source.
                // An event log source should not be created and immediately used.
                // There is a latency time to enable the source, it should be created
                // prior to executing the application that uses the source.
                // Execute this sample a second time to use the new source.
                EventLog.CreateEventSource("MySource", myLogName);
                Console.WriteLine("Creating EventSource");
                Console.WriteLine("Exiting, execute the application a second time to use the source.");
                // The source is created.  Exit the application to allow it to be registered.
                return;
            }
            else
            {
                // Get the EventLog associated if the source exists.
                myLogName = EventLog.LogNameFromSourceName("MySource", ".");
            }

            // Create an EventLog instance and assign its source.
            EventLog myEventLog2 = new EventLog();
            myEventLog2.Source = "MySource";
            // Write an informational entry to the event log.
            myEventLog2.WriteEntry("Successfully created a new Entry in the Log");
            myEventLog2.Close();
            // Create a new EventLog object.
            EventLog myEventLog1 = new EventLog();
            myEventLog1.Log = myLogName;

            // Obtain the Log Entries of "MyNewLog".
            EventLogEntryCollection myEventLogEntryCollection =
               myEventLog1.Entries;
            myEventLog1.Close();
            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);
            }

            // Copy the EventLog entries to Array of type EventLogEntry.
            EventLogEntry[] myEventLogEntryArray =
               new EventLogEntry[myEventLogEntryCollection.Count];
            myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0);
            IEnumerator myEnumerator = myEventLogEntryArray.GetEnumerator();
            while (myEnumerator.MoveNext())
            {
                EventLogEntry myEventLogEntry = (EventLogEntry)myEnumerator.Current;
                Console.WriteLine("The LocalTime the Event is generated is "
                   + myEventLogEntry.TimeGenerated);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception:{0}", e.Message);
        }
    }
}

Uwagi

EventLogEntryCollection Użyj klasy podczas odczytywania wpisów skojarzonych z wystąpieniemEventLog. Właściwość EntriesEventLog klasy jest kolekcją wszystkich wpisów w dzienniku zdarzeń.

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 . Jednak po wyświetleniu całej listy nie zostanie ona zaktualizowana o nowe wpisy.

Właściwości

Count

Pobiera liczbę wpisów w dzienniku zdarzeń (czyli liczbę elementów w kolekcji EventLogEntry ).

Item[Int32]

Pobiera wpis w dzienniku zdarzeń na podstawie indeksu rozpoczynającego się od 0 (zero).

Metody

CopyTo(EventLogEntry[], Int32)

Kopiuje elementy EventLogEntryCollection obiektu do tablicy EventLogEntry wystąpień, zaczynając od określonego indeksu tablicy.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

Obsługuje prostą iterację obiektu EventLogEntryCollection .

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje elementy kolekcji do obiektu Array, zaczynając od określonego Array indeksu.

ICollection.IsSynchronized

Pobiera wartość wskazującą, czy dostęp do elementu EventLogEntryCollection jest synchronizowany (bezpieczny wątkowo).

ICollection.SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do EventLogEntryCollection obiektu.

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy obiektu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Zobacz też