Monday, October 13, 2008

Using the EventLog

Many applications report errors with the EventLog because it provides a simple and centralized way to log. If you use the EventLog you won't have to worry about the size or location of the log.


Some Tips:

Use the EventLog not only for errors. Warnings and other messages are useful in order to understand the application behavior in production environments.

 

If the Source hasn't been created yet, it will be created with the first entry. That operation needs special permissions so, if the application doesn't run with administrator permissions, you must create the Source previously (see EventLogInstaller class).

 

Use some mechanism in order to filter the type of message you want to log. If not, you will have the EventLog full of messages that you don't need. (see TraceSwitch class).

 

Don't forget to use the Event ID. There are many management applications (i.e. MOM/SCOM) that use this information to take different actions.

 

You should document every entry. It will be useful when you are not there to give support.

 

For more details see the EventLog class documentation.

 

0 comments: