Friday, April 15, 2011

Logging in .NET Applications

Logging is very common functionality that needs to be implemented across applications. The main concept for logging is it is common across many applications i.e. the logging remains same across applications. I was missing this idea until i read this article about logging.

"Ideally, the logging functionality would be logically and physically separate from the functionality of each individual page, and adding it to another site would be as simple as dropping an assembly in the site's /bin directory."

Until today i used to use two classes called Errorlog and ErrorLogDB which are the BO and DAO for the logging. I used to copy this classes to any new application i make. I used to write this code in catch block  in every function in every code behind and every method of BL and DAL classes


Old bad way of logging :

catch (Exception ex)
{
    ErrorLog er = new ErrorLog(ex, "functionname""classname");
    ErrorLogDB.Persist(er);
}


. Now i realize how wrong this approach is.

Ok !! Never Late than Never. Lets learn the better way :)



ELMAH: Error Logging Modules And Handlers



Adding ELMAH to an ASP.NET Web Application


No comments:

Post a Comment