EventLog.EntryWritten Evento

Definição

Ocorre quando uma entrada é gravada em um log de eventos no computador local.Occurs when an entry is written to an event log on the local computer.

public:
 event System::Diagnostics::EntryWrittenEventHandler ^ EntryWritten;
public event System.Diagnostics.EntryWrittenEventHandler EntryWritten;
member this.EntryWritten : System.Diagnostics.EntryWrittenEventHandler 
Public Custom Event EntryWritten As EntryWrittenEventHandler 

Tipo de evento

EntryWrittenEventHandler

Exemplos

O exemplo a seguir manipula um evento de entrada gravado.The following example handles an entry written event.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
ref class MySample
{
private:

   // This member is used to wait for events.
   static AutoResetEvent^ signal;

public:
   static void main()
   {
      signal = gcnew AutoResetEvent( false );
      EventLog^ myNewLog = gcnew EventLog;
      myNewLog->Source = "testEventLogEvent";
      myNewLog->EntryWritten += gcnew EntryWrittenEventHandler( MyOnEntryWritten );
      myNewLog->EnableRaisingEvents = true;
      myNewLog->WriteEntry("Test message", EventLogEntryType::Information);
      signal->WaitOne();
   }

   static void MyOnEntryWritten( Object^ /*source*/, EntryWrittenEventArgs^ /*e*/ )
   {
      Console::WriteLine("In event handler");
      signal->Set();
   }

};

int main()
{
   MySample::main();
}

using System;
using System.Diagnostics;
using System.Threading;

class MySample{

    // This member is used to wait for events.
    static AutoResetEvent signal;

    public static void Main(){

        signal = new AutoResetEvent(false);
        EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");

        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;
        myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
        signal.WaitOne();
    }

    public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){
        Console.WriteLine("In event handler");
        signal.Set();
    }
}

Option Explicit On 
Option Strict On

Imports System.Diagnostics
Imports System.Threading


Class MySample

    ' This member is used to wait for events.
    Private Shared signal As AutoResetEvent


    Public Shared Sub Main()

        signal = New AutoResetEvent(False)
        Dim myNewLog As New EventLog("Application", ".", "testEventLogEvent")

        AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
        myNewLog.EnableRaisingEvents = True
        myNewLog.WriteEntry("Test message", EventLogEntryType.Information)

        signal.WaitOne()
    End Sub


    Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
        Console.WriteLine("In event handler")
        signal.Set()
    End Sub
End Class

Comentários

Para obter notificações de eventos, você deve definir EnableRaisingEvents como true .To get event notifications, you must set EnableRaisingEvents to true. Você só pode receber notificações de eventos quando as entradas são gravadas no computador local.You can only receive event notifications when entries are written on the local computer. Você não pode receber notificações para entradas gravadas em computadores remotos.You cannot receive notifications for entries written on remote computers.

Ao criar um EntryWritten delegado, você identifica o método que manipulará o evento.When you create an EntryWritten delegate, you identify the method that will handle the event. Para associar o evento ao manipulador de eventos, adicione uma instância do delegado ao evento.To associate the event with your event handler, add an instance of the delegate to the event. O manipulador de eventos é chamado sempre que o evento ocorre, até que você remova o delegado.The event handler is called whenever the event occurs, until you remove the delegate. Para obter mais informações sobre como manipular eventos com delegados, consulte manipulando e gerando eventos.For more information about handling events with delegates, see Handling and Raising Events.

O sistema responderá WriteEntry somente se o último evento de gravação tiver ocorrido pelo menos seis segundos antes.The system responds to WriteEntry only if the last write event occurred at least six seconds previously. Isso implica que você receberá apenas uma EntryWritten notificação de evento dentro de um intervalo de seis segundos, mesmo que ocorra mais de uma alteração no log de eventos.This implies you will only receive one EntryWritten event notification within a six-second interval, even if more than one event log change occurs. Se você inserir um intervalo de suspensão suficientemente longo (cerca de 10 segundos) entre chamadas para WriteEntry , será menos provável que você perca um evento.If you insert a sufficiently long sleep interval (around 10 seconds) between calls to WriteEntry, you are less likely to miss an event. No entanto, se eventos de gravação ocorrerem com mais frequência, você poderá não receber a notificação de eventos até o próximo intervalo.However, if write events occur more frequently, you might not receive the event notification until the next interval. Normalmente, as notificações de eventos perdidas não são perdidas, mas atrasadas.Typically, missed event notifications are not lost, but delayed.

Aplica-se a

Confira também