EventLog.EnableRaisingEvents Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą EventLog , czy odbiera EntryWritten powiadomienia o zdarzeniach.

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

Wartość właściwości

trueEventLog jeśli otrzyma powiadomienie, gdy wpis zostanie zapisany w dzienniku; w przeciwnym razie . false

Atrybuty

Wyjątki

Dziennik zdarzeń znajduje się na komputerze zdalnym.

Przykłady

Poniższy przykład obsługuje EntryWritten zdarzenie.

#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

Uwagi

Właściwość EnableRaisingEvents określa, czy zgłasza EventLog zdarzenia, gdy wpisy są zapisywane w dzienniku. Gdy właściwość ma truewartość , składniki odbierające EntryWritten zdarzenie będą otrzymywać powiadomienia za każdym razem, gdy wpis zostanie zapisany w dzienniku Log określonym we właściwości . Jeśli EnableRaisingEvents parametr ma falsewartość , żadne zdarzenia nie są zgłaszane.

Uwaga

Powiadomienia o zdarzeniach można odbierać tylko wtedy, gdy wpisy są zapisywane na komputerze lokalnym. Nie można odbierać powiadomień o wpisach zapisanych na komputerach zdalnych.

Dotyczy

Zobacz też