Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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
<BrowsableAttribute(False)> _
<MonitoringDescriptionAttribute("LogMonitoring")> _
Public Property EnableRaisingEvents As Boolean

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.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft