Exportar (0) Imprimir
Expandir todo

EventLogEntryCollection (Clase)

Define el tamaño y los enumeradores de una colección de instancias de EventLogEntry.

Espacio de nombres: System.Diagnostics
Ensamblado: System (en system.dll)

public class EventLogEntryCollection : ICollection, IEnumerable
public class EventLogEntryCollection implements ICollection, IEnumerable
public class EventLogEntryCollection implements ICollection, IEnumerable

Utilice la clase EventLogEntryCollection cuando lea las entradas asociadas a una instancia de EventLog. La propiedad Entries de la clase EventLog es una colección de todas las entradas del registro de eventos.

Dado que las nuevas entradas se agregan al final de la lista, el recorrido paso a paso por la colección permite el acceso a las entradas creadas después de EventLogEntryCollection. Sin embargo, una vez examinada toda la lista, ésta no se actualiza con nuevas entradas.

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 source.
            EventLog.CreateEventSource("MySource", myLogName);
            Console.WriteLine("Creating EventSource");
         }
         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);
      }
   }
}

import System.*;
import System.Collections.*;
import System.Diagnostics.*;

class EventLogEntryCollectionItem
{
    public static void main(String[] args)
    {
        try {
            String myLogName = "MyNewLog";

            // Check if the source exists.
            if (!(EventLog.SourceExists("MySource"))) {
                //Create source.
                EventLog.CreateEventSource("MySource", myLogName);
                Console.WriteLine("Creating EventSource");
            }
            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.set_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.set_Log(myLogName);

            // Obtain the Log Entries of "MyNewLog".
            EventLogEntryCollection myEventLogEntryCollection = 
                myEventLog1.get_Entries();

            myEventLog1.Close();
            Console.WriteLine("The number of entries in 'MyNewLog' = " 
                + myEventLogEntryCollection.get_Count());

            // Display the 'Message' property of EventLogEntry.
            for (int i = 0; i < myEventLogEntryCollection.get_Count(); i++) {
                Console.WriteLine("The Message of the EventLog is :"
                    + myEventLogEntryCollection.get_Item(i).get_Message());
            }
            // Copy the EventLog entries to Array of type EventLogEntry.
            EventLogEntry myEventLogEntryArray[] = 
                new EventLogEntry[myEventLogEntryCollection.get_Count()];

            myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0);
            IEnumerator myEnumerator = myEventLogEntryArray.GetEnumerator();
            while (myEnumerator.MoveNext()) {
                EventLogEntry myEventLogEntry = 
                    (EventLogEntry)myEnumerator.get_Current();
                Console.WriteLine("The LocalTime the Event is generated is " 
                    + myEventLogEntry.get_TimeGenerated());
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception:{0}", e.get_Message());
        }
    } //main
} //EventLogEntryCollectionItem

System.Object
  System.Diagnostics.EventLogEntryCollection

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft