This documentation is archived and is not being maintained.

EventLog.EnableRaisingEvents Property

Gets or sets a value indicating whether the EventLog receives EntryWritten event notifications.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

'Declaration
Public Property EnableRaisingEvents As Boolean
'Usage
Dim instance As EventLog
Dim value As Boolean

value = instance.EnableRaisingEvents

instance.EnableRaisingEvents = value
/** @property */
public boolean get_EnableRaisingEvents ()

/** @property */
public void set_EnableRaisingEvents (boolean value)

public function get EnableRaisingEvents () : boolean

public function set EnableRaisingEvents (value : boolean)

Not applicable.

Property Value

true if the EventLog receives notification when an entry is written to the log; otherwise, false.

Exception typeCondition

InvalidOperationException

The event log is on a remote computer.

The EnableRaisingEvents property determines whether the EventLog raises events when entries are written to the 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. If EnableRaisingEvents is false, no events are raised.

NoteNote:

You can receive event notifications only when entries are written on the local computer. You cannot receive notifications for entries written on remote computers.

The following example handles an EntryWritten event.

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

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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: