Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between EventLog.WriteEntry and EventLog.WriteEvent methods

Tags:

.net

.net-2.0

I tried using WriteEntry and WriteEvent methods of EventLog class.

EventLog.WriteEntry("Saravanan", "Application logs an entry",                       EventLogEntryType.Information, 2, 3); EventLog.WriteEvent("Saravanan",  new EventInstance(2, 3),                                   "Application logs an event"); 

Both output the same result.

Is there any difference in usage of these methods?

If there are only minor difference, why was it not done through a overload of either WriteEvent() or WriteEntry() methods, instead of introducing a new method?

like image 979
SaravananArumugam Avatar asked Aug 30 '10 11:08

SaravananArumugam


People also ask

What are the parameters does EventLog WriteEntry support?

WriteEntry(String, String, EventLogEntryType, Int32, Int16) Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, using the specified registered event source. The category can be used by the Event Viewer to filter events in the log.

Which of the following methods can be used to delete an EventLog object?

You can use the static members of EventLog to delete logs, get log lists, create or delete a source, or determine if a computer already contains a particular source. There are three default event logs: Application, System, and Security.


1 Answers

EventLog.WriteEntry is a "quick and dirty" way to write to the event log where you can write a string. EventLog.WriteEvent enables you to take full advantage of the native Win32 API. However, to do that you are supposed to create a localized message file you then compile using the message compiler (mc.exe). Each event can contain substitution strings and can be localized to match the locale on the computer.

To avoid this extra step of creating a message file the .Net wrapper for the event log API use messages that simply inserts the strings supplied as arguments. These message are used by EventLog.WriteEntry and are stored as embedded resources in EventLogMessages.dll in the .Net folder.

Normally using EventLog.WriteEntry is adequate, but if you need to localize your messages or want to maintain them outside your source code you should create a message file and use EventLog.WriteEvent.

like image 142
Martin Liversage Avatar answered Sep 19 '22 19:09

Martin Liversage