EventLog.EnableRaisingEvents Proprietà

Definizione

Ottiene o imposta un valore che indica se EventLog riceve notifiche dell'evento EntryWritten.

public:
 property bool EnableRaisingEvents { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool EnableRaisingEvents { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.EnableRaisingEvents : bool with get, set
Public Property EnableRaisingEvents As Boolean

Valore della proprietà

true se l'oggetto EventLog riceve notifica quando una voce viene inserita nel log; in caso contrario, false.

Attributi

Eccezioni

Il registro eventi si trova su un computer remoto.

Esempio

Nell'esempio seguente viene gestito un EntryWritten evento.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
ref class MySample
{
public:
   static void MyOnEntryWritten( Object^ /*source*/, EntryWrittenEventArgs^ e )
   {
      Console::WriteLine( "Written: {0}", e->Entry->Message );
   }

};

int main()
{
   EventLog^ myNewLog = gcnew EventLog;
   myNewLog->Log = "MyCustomLog";
   myNewLog->EntryWritten += gcnew EntryWrittenEventHandler( MySample::MyOnEntryWritten );
   myNewLog->EnableRaisingEvents = true;
   Console::WriteLine( "Press \'q\' to quit." );
   
   // Wait for the EntryWrittenEvent or a quit command.
   while ( Console::Read() != 'q' )
   {
      
      // Wait.
   }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample{

    public static void Main(){

        EventLog myNewLog = new EventLog();
        myNewLog.Log = "MyCustomLog";

        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;

        Console.WriteLine("Press \'q\' to quit.");
        // Wait for the EntryWrittenEvent or a quit command.
        while(Console.Read() != 'q'){
            // Wait.
        }
    }

    public static void MyOnEntryWritten(Object source, EntryWrittenEventArgs e){
        Console.WriteLine("Written: " + e.Entry.Message);
    }
}
Option Strict
Option Explicit

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        
        Dim myNewLog As New EventLog()
        myNewLog.Log = "MyCustomLog"
        
        AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
        myNewLog.EnableRaisingEvents = True
        
        
        Console.WriteLine("Press 'q' to quit.")
        ' Wait for the EntryWrittenEvent or a quit command.
        While Char.ToLower(Convert.ToChar(Console.Read()))<>"q"
            ' Wait.
        End While 
    End Sub
    
    Public Shared Sub MyOnEntryWritten(source As Object, e As EntryWrittenEventArgs)
        Console.WriteLine(("Written: " + e.Entry.Message))
    End Sub
End Class

Commenti

La EnableRaisingEvents proprietà determina se gli eventi generano quando le EventLog voci vengono scritte nel log. Quando la proprietà è true, i componenti che ricevono l'evento EntryWritten riceveranno una notifica qualsiasi volta che una voce viene scritta nel log specificato nella Log proprietà. Se EnableRaisingEvents è false, non vengono generati eventi.

Nota

È possibile ricevere notifiche degli eventi solo quando le voci vengono scritte nel computer locale. Non è possibile ricevere notifiche per le voci scritte nei computer remoti.

Si applica a

Vedi anche