views:

142

answers:

3

What is an application log? How is it different from Error Log? What kind of information should Application log file contain. Are there any built in classes which I can use for that?

A: 

In an application log you record information you deem will be helpful to you when a problem occurs. There are simple ways to do it but for a more formal approach you can take a look at Microsoft's Enterprise Library from the Patterns and Practices group which will provide you with the source code that you can use as is or modify it to adjust to your needs.

jvanderh
+1  A: 

You can use System.Diagnostics.EventLog to write to the log in Windows. The type of information you put in there is up to you, depending on what you need in your app. You can class log entries by EventLogEntryType (error, information, warning, etc).

Jon B
You can also classify events by error/event code which is extremely helpful when debugging services. For example, you can assign an event code to each procedure in the service.
AMissico
+2  A: 

I highly recommend log4net.

An application log records whatever you tell it to record. One big advantage is that you can choose what information to record, so you can log system state, current user, and other parameters of your choosing. The event log is not as flexible. Logging frameworks typically let you record events that happen at different levels, but it's up to you to define what those levels mean in your code. The log level is set through configuration, so it is DEBUG on our dev system and WARN on our prod system. These are my definitions for the log4net levels:

DEBUG - Tracing, etc., use at will
INFO - System state info, important/useful info that you don't care to see in the production log
WARN - Handled exceptions, rare events, unusual code branches taken
ERROR - Caught but unhandled exceptions
FATAL - Only used in global handler
Jamie Ide