EventLog.EnableRaisingEvents 属性

获取或设置一个值,用以指示 EventLog 是否接收 EntryWritten 事件通知。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public Property EnableRaisingEvents As Boolean
用法
Dim instance As EventLog
Dim value As Boolean

value = instance.EnableRaisingEvents

instance.EnableRaisingEvents = value
public bool EnableRaisingEvents { get; set; }
public:
property bool EnableRaisingEvents {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_EnableRaisingEvents ()

/** @property */
public void set_EnableRaisingEvents (boolean value)
public function get EnableRaisingEvents () : boolean

public function set EnableRaisingEvents (value : boolean)

属性值

如果 EventLog 在有项写入日志时接收通知,则为 true;否则为 false

备注

EnableRaisingEvents 属性确定在向日志写入项时 EventLog 是否引发事件。当该属性为 true 时,每当有项写入 Log 属性指定的日志时,接收 EntryWritten 事件的组件都将收到通知。如果 EnableRaisingEventsfalse,则不引发事件。

示例

下面的示例处理 EntryWritten 事件。

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
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);
    }
}
#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.
   }
}
import System.*;
import System.Diagnostics.*;
import System.Threading.*;

class MySample
{
    public static void main(String[] args)
    {
        EventLog myNewLog = new EventLog();
        myNewLog.set_Log("MyCustomLog");
        myNewLog.add_EntryWritten(new EntryWrittenEventHandler(
            MyOnEntryWritten));
        myNewLog.set_EnableRaisingEvents(true);
        Console.WriteLine("Press \'q\' to quit.");

        // Wait for the EntryWrittenEvent or a quit command.
        while (Console.Read() != 'q') {
            // Wait.
        } 
    } //main

    private static void MyOnEntryWritten(Object source, EntryWrittenEventArgs e)
    {
        Console.WriteLine("Written: " + e.get_Entry().get_Message());
    } //MyOnEntryWritten
} //MySample

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

EventLog 类
EventLog 成员
System.Diagnostics 命名空间
EntryWritten