EventLog.EnableRaisingEvents Property
Gets or sets a value indicating whether the EventLog receives EntryWritten event notifications.
[Visual Basic] Public Property EnableRaisingEvents As Boolean [C#] public bool EnableRaisingEvents {get; set;} [C++] public: __property bool get_EnableRaisingEvents(); public: __property void set_EnableRaisingEvents(bool); [JScript] public function get EnableRaisingEvents() : Boolean; public function set EnableRaisingEvents(Boolean);
Property Value
true if the EventLog receives notification when an entry is written to the log; otherwise, false.
Remarks
The EnableRaisingEvents property determines whether the EventLog raises events when entries are written to the log. When the property is true, components receiving the EntryWritten event will receive notification any time an entry is written to the log specified in the Log property. If EnableRaisingEvents is false, no events are raised.
Example
[Visual Basic, C#, C++] The following example handles an EntryWritten event.
[Visual Basic] 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 [C#] 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); } } [C++] #using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; __gc class MySample{ public: static void MyOnEntryWritten(Object* /*source*/, EntryWrittenEventArgs* e){ Console::WriteLine(S"Written: {0}", e->Entry->Message); } }; int main(){ EventLog* myNewLog = new EventLog(); myNewLog->Log = S"MyCustomLog"; myNewLog->EntryWritten += new EntryWrittenEventHandler(0, MySample::MyOnEntryWritten); myNewLog->EnableRaisingEvents = true; Console::WriteLine(S"Press \'q\' to quit."); // Wait for the EntryWrittenEvent or a quit command. while(Console::Read() != 'q'){ // Wait. } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- SecurityPermission for calling any members of EventLog with full trust. Associated enumeration: PermissionState.Unrestricted
See Also
EventLog Class | EventLog Members | System.Diagnostics Namespace | EntryWritten