Answered by:
EventLog.EntryWritten and Event Log Overwrite as Needed

Question
-
I'm having an issue watching event logs on computers. I catch the events fine with the simple code from here: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten.aspx
using System; using System.Diagnostics; using System.Threading; class MySample{ // This member is used to wait for events. static AutoResetEvent signal; public static void Main(){ signal = new AutoResetEvent(false); EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent"); myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten); myNewLog.EnableRaisingEvents = true; myNewLog.WriteEntry("Test message", EventLogEntryType.Information); signal.WaitOne(); } public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){ Console.WriteLine("In event handler"); //signal.Set(); } }
The issue is that when the event log on the computer is set to overwrite as needed, it seems to "lose" my EventLog object in the EntryWritten handler. EntryWrittenEventArgs ends up without any usable data. This is repeatable on any computer.
Is there some way to know when the event log is overwritting itself?
Thanks.
If everyone is thinking alike, then somebody isn't thinking.- Moved by Leo Liu - MSFT Wednesday, March 30, 2011 2:05 AM Off-topic (From:Visual C# General)
Wednesday, March 23, 2011 4:57 PM
Answers
-
If it is proved to be an issue, you can submit your suggestion to Microsoft Connect feedback portal http://connect.microsoft.com, Microsoft engineers will evaluate it seriously. If this issue is urgent, please contact support at http://support.microsoft.com. Thanks.
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:27 AM
Wednesday, March 30, 2011 2:04 AM -
This was moved out of the VC# forum.
You can ask this at www.answers.micorosft.com or in another forum.
Or I can move it into a specific MSDN/TechNet forum if you'd like.
This is regarding your event log code:
using System; using System.Diagnostics; using System.Threading; class MySample{ static AutoResetEvent signal; public static void Main(){ signal = new AutoResetEvent(false); EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent"); myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten); myNewLog.EnableRaisingEvents = true; myNewLog.WriteEntry("Test message", EventLogEntryType.Information); signal.WaitOne();
Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:30 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:30 AM
Saturday, December 31, 2011 12:29 AM
All replies
-
Hi Justin,
See following thread, it might be helpfull.
Thanks,
Mubi
Mubi | www.mrmubi.com | Mark The Best Replies As Answers!Wednesday, March 23, 2011 5:52 PM -
Hi Justin,
See following thread, it might be helpfull.
Thanks,
Mubi
Mubi | www.mrmubi.com | Mark The Best Replies As Answers!Thank Mubi, but unfortunately that doesn't address how to handle it. If it happens to overwrite while I'm waiting for events, MyOnEntryWritten will stop working because e.Entry seems to lose its attachment to the event log. Meaning that any property of e.Entry is missing data.
I'm really at a loss here. I've tried looking at the native API, but I'm not sure that would help here. Surely I can't be the only one?
If everyone is thinking alike, then somebody isn't thinking.Wednesday, March 23, 2011 7:51 PM -
Any other ideas out there? Surely I can't be the one person who ran into this issue?
If everyone is thinking alike, then somebody isn't thinking.Monday, March 28, 2011 1:28 PM -
I'd like to suggest that you post your thread in the .NET Base Class Library Forum for better support if you could not get exact what you want here.
Then I will move your thread into the Off-Topic Forum shortly. Thanks.
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, March 29, 2011 4:38 AM -
I posted it in the suggested forum. Hopefully someone has a solution. Seems almost like a "bug".
If everyone is thinking alike, then somebody isn't thinking.Tuesday, March 29, 2011 3:53 PM -
If it is proved to be an issue, you can submit your suggestion to Microsoft Connect feedback portal http://connect.microsoft.com, Microsoft engineers will evaluate it seriously. If this issue is urgent, please contact support at http://support.microsoft.com. Thanks.
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:27 AM
Wednesday, March 30, 2011 2:04 AM -
I filed a report: https://connect.microsoft.com/VisualStudio/feedback/details/654644/eventlog-entrywritten-and-event-log-overwrite-as-needed-problems
Hopefully someone takes a look at it.
If everyone is thinking alike, then somebody isn't thinking.Wednesday, March 30, 2011 11:15 AM -
This was moved out of the VC# forum.
You can ask this at www.answers.micorosft.com or in another forum.
Or I can move it into a specific MSDN/TechNet forum if you'd like.
This is regarding your event log code:
using System; using System.Diagnostics; using System.Threading; class MySample{ static AutoResetEvent signal; public static void Main(){ signal = new AutoResetEvent(false); EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent"); myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten); myNewLog.EnableRaisingEvents = true; myNewLog.WriteEntry("Test message", EventLogEntryType.Information); signal.WaitOne();
Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:30 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Saturday, December 31, 2011 12:30 AM
Saturday, December 31, 2011 12:29 AM