System.Diagnostics.EventLogEntry and the non-equal Equals.
Just a quick heads-up in case you're stumped with this problem, or just passing by:
The System.Diagnostics.EventLogEntry class implements the Equals method to check if two entries are identical, even if they're not the same instance. However, contrary to best practices, it does NOT overload the operator==, so these two bits of code will behave differently:
EventLog myEventLog = new EventLog("Application"); EventLogEntry entry1 = myEventLog.Entries[0]; EventLogEntry entry2 = myEventLog.Entries[0]; bool correct = entry1.Equals(entry2); bool incorrect = entry1 == entry2;
After running this code, correct will be true while incorrect will be false.
Good to know, if you're reading event logs in your code.
3 Comments
Comments have been disabled for this content.
AndrewSeven said
Some are just more equal than others :P
Avner Kashtan said
Andrew: Man, I should have used that one. It was just lying there waiting for me, and I missed it. :)
Moncler said
This is a Professional blog,great you can write so beautiful.