EventLog.EnableRaisingEvents Vlastnost

Definice

Získá nebo nastaví hodnotu označující, zda EventLog přijímá oznámení o událostech 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

Hodnota vlastnosti

true pokud obdrží EventLog oznámení, když je záznam zapsán do protokolu; v opačném případě false.

Atributy

Výjimky

Protokol událostí je ve vzdáleném počítači.

Příklady

Následující příklad zpracovává EntryWritten událost.

#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

Poznámky

Vlastnost EnableRaisingEvents určuje, jestli EventLog vyvolá události při zápisu položek do protokolu. Pokud je truevlastnost , komponenty, které obdrží EntryWritten událost, obdrží oznámení pokaždé, když je položka zapsána do protokolu, který je zadán ve Log vlastnosti . Pokud EnableRaisingEvents je false, nevyvolají se žádné události.

Poznámka

Oznámení o událostech můžete přijímat pouze v případě, že jsou položky zapsány v místním počítači. Nelze přijímat oznámení pro položky zapsané ve vzdálených počítačích.

Platí pro

Viz také