Microsoft KB Archive/328380

= BUG: EntryWritten Event Stops Occurring After EventLog.Clear Method Is Called =

Article ID: 328380

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft .NET Framework 1.1
 * Microsoft Platform Software Development Kit-January 2000 Edition
 * Microsoft .NET Framework Class Libraries 1.0
 * Microsoft .NET Framework Class Libraries 1.1

-



This article was previously published under Q328380



SYMPTOMS
You can use an EventLog object to receive notification when new entries are added to an event log. To do this, assign an EntryWrittenEventHandler delegate to the EventLog.EntryWritten event, and then set the EventLog.EnableRaisingEvents property to True.

The problem occurs after you call the EventLog.Clear method, which causes the EventLog.EnableRaisingEvents property to be set to False. Even after you reset this property to True, the EntryWritten event does not fire again until the count of records in the log exceeds the number of records that were present before the log was cleared.



RESOLUTION
To work around this problem, you must create a new EventLog object after you call the EventLog.Clear method.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The following C# sample code demonstrates how to work around this problem: create a new EventLog object after you call the EventLog.Clear method. using System; using System.Diagnostics; using System.Threading; class MySample {  static EventLog MyLog;

public static void Main {     // Create an EventLog object. MyLog = new EventLog(&quot;MyApplicationLog&quot;);

// Attach a delegate to the EntryWritten event. MyLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten); MyLog.EnableRaisingEvents = true;

// Add other application code.

// At some point, clear the log. MyLog.Clear;

// After you clear the log, immediately create a new EventLog object. MyLog = new EventLog(&quot;MyApplicationLog&quot;);

// Again, attach the delegate to the EntryWritten event. MyLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten); MyLog.EnableRaisingEvents = true; // Continue program execution.

}

public static void OnEntryWritten(object source,                                     EntryWrittenEventArgs e)   { Console.WriteLine(e.Entry.Message); } }

Keywords: kbbug kbeventlog kbkernbase kbpending KB328380

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.