EnableRaisingEvents Property

EventLog.EnableRaisingEvents Property

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

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

[BrowsableAttribute(false)]
public bool EnableRaisingEvents { get; set; }

Property Value

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

ExceptionCondition
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.

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);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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

Community Additions

ADD
Show:
© 2016 Microsoft