EventLogEntryCollection 클래스

정의

EventLogEntry 인스턴스의 컬렉션에 대한 크기 및 열거자를 정의합니다.

public ref class EventLogEntryCollection : System::Collections::ICollection
public class EventLogEntryCollection : System.Collections.ICollection
type EventLogEntryCollection = class
    interface ICollection
    interface IEnumerable
Public Class EventLogEntryCollection
Implements ICollection
상속
EventLogEntryCollection
구현

예제

다음 예제에서는 개체에서 EventLogEntryCollection 이벤트 로그 정보를 가져오는 방법을 보여 줍니다.

#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Diagnostics;
int 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
            myLogName = EventLog::LogNameFromSourceName( "MySource", "." );
      
      // Get the EventLog associated if the source exists.
      // Create an EventLog instance and assign its source.
      EventLog^ myEventLog2 = gcnew 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 = gcnew EventLog;
      myEventLog1->Log = myLogName;
      
      // Obtain the Log Entries of S"MyNewLog".
      EventLogEntryCollection^ myEventLogEntryCollection = myEventLog1->Entries;
      myEventLog1->Close();
      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 );
      }
      
      // Copy the EventLog entries to Array of type EventLogEntry.
      array<EventLogEntry^>^myEventLogEntryArray = gcnew array<EventLogEntry^>(myEventLogEntryCollection->Count);
      myEventLogEntryCollection->CopyTo( myEventLogEntryArray, 0 );
      IEnumerator^ myEnumerator = myEventLogEntryArray->GetEnumerator();
      while ( myEnumerator->MoveNext() )
      {
         EventLogEntry^ myEventLogEntry = safe_cast<EventLogEntry^>(myEnumerator->Current);
         Console::WriteLine( "The LocalTime the Event is generated is {0}", myEventLogEntry->TimeGenerated );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}
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);
        }
    }
}
Imports System.Collections
Imports System.Diagnostics

Class EventLogEntryCollection_Item
   Public Shared Sub Main()
      Try
         Dim myLogName As String = "MyNewlog"
         ' Check if the source exists.
         If Not EventLog.SourceExists("MySource") Then
            'Create source.
            EventLog.CreateEventSource("MySource", myLogName)
            Console.WriteLine("Creating EventSource")
         ' Get the EventLog associated if the source exists.
         Else
            myLogName = EventLog.LogNameFromSourceName("MySource", ".")
         End If
         ' Create an EventLog instance and assign its source.
         Dim myEventLog2 As 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.
         Dim myEventLog1 As New EventLog()
         myEventLog1.Log = myLogName

         ' Obtain the Log Entries of "MyNewLog".
         Dim myEventLogEntryCollection As EventLogEntryCollection = myEventLog1.Entries
         myEventLog1.Close()
         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
         ' Copy the EventLog entries to Array of type EventLogEntry.
         Dim myEventLogEntryArray(myEventLogEntryCollection.Count-1) As EventLogEntry
         myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0)
         Dim myEnumerator As IEnumerator = myEventLogEntryArray.GetEnumerator()
         While myEnumerator.MoveNext()
            Dim myEventLogEntry As EventLogEntry = CType(myEnumerator.Current, EventLogEntry)
            Console.WriteLine("The LocalTime the Event is generated is " + _
                                 myEventLogEntry.TimeGenerated)
         End While
      Catch e As Exception
         Console.WriteLine("Exception:{0}", e.Message.ToString())
      End Try
   End Sub
End Class

설명

EventLogEntryCollection 인스턴스와 연결된 항목을 읽을 때 클래스를 EventLog 사용합니다. Entries 클래스의 EventLog 속성은 이벤트 로그에 있는 모든 항목의 컬렉션입니다.

새 항목이 기존 목록에 추가되므로 컬렉션을 단계별로 실행하면 원래 을 만든 후에 만든 항목에 EventLogEntryCollection액세스할 수 있습니다. 그러나 전체 목록을 확인한 후에는 새 항목으로 업데이트되지 않습니다.

속성

Count

이벤트 로그의 엔트리 수, 즉 EventLogEntry 컬렉션의 요소 수를 가져옵니다.

Item[Int32]

0부터 시작하는 인덱스를 기준으로 이벤트 로그에 있는 엔트리를 가져옵니다.

메서드

CopyTo(EventLogEntry[], Int32)

특정 배열 인덱스부터 시작하여 EventLogEntryCollection 요소를 EventLogEntry 인스턴스의 배열에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

EventLogEntryCollection 개체의 단순 반복을 지원합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

특정 Array 인덱스부터 시작하여 컬렉션의 요소를 Array에 복사합니다.

ICollection.IsSynchronized

EventLogEntryCollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

EventLogEntryCollection 개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보