다음을 통해 공유


방법: EntryWritten 이벤트 처리

업데이트: 2007년 11월

로그에 엔트리가 기록되면 자동으로 프로시저를 호출하는 EventLog 구성 요소의 이벤트 처리기를 만들 수 있습니다. EventLog 구성 요소 인스턴스의 이벤트 처리기를 만들 수 있는 방법은 여러 가지가 있지만 가장 간단한 방법은 Visual Studio에서 자동으로 대부분의 구문을 처리하도록 하는 것입니다. 디자이너에서 EventLog 구성 요소를 두 번 클릭하면 Visual Studio에서 코드 편집기가 열리고 이벤트 처리기와 이 이벤트 처리기가 호출하는 빈 프로시저가 만들어집니다. 그러면 EntryWritten 이벤트 처리기에서 발생시키려는 프로세싱을 채울 수 있습니다.

이벤트 처리기에 대한 자세한 내용은 이벤트 처리 및 발생을 참조하십시오.

EntryWritten 이벤트의 기본 처리기를 만들려면

  1. 디자이너에서 처리기를 만들 EventLog 구성 요소를 두 번 클릭합니다.

    참고:

    코드 편집기가 나타나고 두 항목이 코드에 추가되어 있습니다. 즉, 대리자를 만들어 등록하고 프로시저를 호출하는 처리기와 EntryWritten 이벤트의 빈 프로시저가 코드에 추가되어 있습니다.

  2. EntryWritten 이벤트의 빈 프로시저에서, 이 이벤트가 호출될 때 엔트리를 수신하고 처리하는 코드를 정의합니다. 코드는 다음과 비슷합니다.

    Private Sub EventLog1_EntryWritten(ByVal sender As System.Object, ByVal e As System.Diagnostics.EntryWrittenEventArgs) Handles EventLog1.EntryWritten
        If e.Entry.Source = "MyApplication" Then
            Console.WriteLine("Entry written by my app. Message: " & _
               e.Entry.Message)
        Else
            Console.WriteLine("Entry written by another application. ")
        End If
    End Sub
    
     private void eventLog1_EntryWritten(object sender, System.Diagnostics.EntryWrittenEventArgs e)
        {
            if (e.Entry.Source == "MyApplication")
                Console.WriteLine("Entry written by my application. Message: "
                   + e.Entry.Message);
            else
                Console.WriteLine("Entry was written by another application.");
        }
    
  3. EnableRaisingEvents 속성을 true로 설정합니다.

프로그래밍 방식으로 처리기를 만들려면

  1. AddHandler 메서드를 사용하여 엔트리가 로그에 기록될 때 eventLog1_EntryWritten 메서드를 호출할 구성 요소에 사용할 EntryWrittenEventHandler 형식의 이벤트 처리기를 만듭니다. 코드는 다음과 같습니다.

    Public Sub method5()
        AddHandler EventLog1.EntryWritten, _
           New System.Diagnostics.EntryWrittenEventHandler( _
           AddressOf Me.EventLog1_EntryWritten)
    
         this.eventLog1.EntryWritten += new
               System.Diagnostics.EntryWrittenEventHandler(
               this.eventLog1_EntryWritten);
    
    참고:

    이 구문에 대한 자세한 내용은 이벤트 처리 및 발생을 참조하십시오.

  2. EntryWritten 프로시저를 만들고 엔트리를 처리할 코드를 정의합니다.

  3. EnableRaisingEvents 속성을 true로 설정합니다.

참고 항목

작업

방법: EventLog 구성 요소 인스턴스 구성

방법: EventLog 구성 요소 인스턴스 구성

기타 리소스

이벤트 처리 및 발생