共用方式為


EventLog.EnableRaisingEvents 屬性

定義

取得或設定值,表示 EventLog 是否接收 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

屬性值

如果 EventLog 在項目寫入到記錄檔時接收通知,則為 true,否則為 false

屬性

例外狀況

事件記錄位於遠端電腦上。

範例

下列範例會處理 EntryWritten 事件。

#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

備註

屬性 EnableRaisingEvents 會決定 當專案寫入記錄檔時,是否 EventLog 引發事件。 當 屬性為 true時,接收 EntryWritten 事件的元件會在每次將專案寫入屬性中指定的 Log 記錄檔時收到通知。 如果 為 EnableRaisingEventsfalse,則不會引發任何事件。

注意

只有在本機計算機上寫入專案時,才可以接收事件通知。 您無法收到遠端電腦上寫入專案的通知。

適用於

另請參閱