EventLog.EnableRaisingEvents EventLog.EnableRaisingEvents EventLog.EnableRaisingEvents EventLog.EnableRaisingEvents Property

定義

取得或設定值,表示 EventLog 是否接收 EntryWritten 事件通知。Gets or sets a value indicating whether the EventLog receives EntryWritten event notifications.

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

屬性值

如果 EventLog 在項目寫入到記錄檔時接收通知,則為 true,否則為 falsetrue if the EventLog receives notification when an entry is written to the log; otherwise, false.

例外狀況

事件記錄位於遠端電腦上。The event log is on a remote computer.

範例

下列範例會處理EntryWritten事件。The following example handles an EntryWritten event.

#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
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 ' Main
    
    Public Shared Sub MyOnEntryWritten(source As Object, e As EntryWrittenEventArgs)
        Console.WriteLine(("Written: " + e.Entry.Message))
    End Sub ' MyOnEntryWritten
End Class ' MySample

備註

EnableRaisingEvents屬性會決定是否EventLog引發事件時寫入記錄檔項目。The EnableRaisingEvents property determines whether the EventLog raises events when entries are written to the log. 將屬性何時true,會收到的元件EntryWritten事件將會收到通知任何時間項目會寫入至記錄檔中指定Log屬性。When the property is true, components that receive the EntryWritten event will receive notification any time an entry is written to the log that is specified in the Log property. 如果EnableRaisingEventsfalse,不會引發事件。If EnableRaisingEvents is false, no events are raised.

注意

只有當項目會寫入本機電腦上,您可以接收事件通知。You can receive event notifications only when entries are written on the local computer. 您無法接收通知的遠端電腦上寫入的項目。You cannot receive notifications for entries written on remote computers.

安全性

EventLogPermission
用於寫入在電腦上的事件記錄檔資訊。for writing the event log information on the computer. 相關聯的列舉型別: WriteAssociated enumeration: Write

適用於

另請參閱