How can I keep all exceptions in the database without calling a function throughout the whole project in .Net?

I want to keep all exception logs in a database in .NET. It is very important to insert exceptions into the database in every try catch block. Is there any possible general permanent solution? Is there any service that starts on every exception is thrown in black try / catch so that I modify that service and insert every exception into the database?

+3


source to share


2 answers


You can try putting some logic on an event Application_Error

Global.asax

in your project files. This will run every time an unhandled error occurs.

Something like this would help:

void Application_Error(object sender, EventArgs e)
{
  // Code that runs when an unhandled error occurs

  // Get the exception object.
  Exception exc = Server.GetLastError();

  //handle your exception here.
}

      



Also, since its requirement is fine, otherwise it is not a bad idea to write different blocks of exception code for different functions, since you might handle some exceptions differently than others.

Hope it helps.

+5


source


You can save all exceptions to the database using ELMAH OR log4net

Here is the link:



http://www.asp.net/web-forms/overview/older-versions-getting-started/deploying-web-site-projects/logging-error-details-with-elmah-cs

I hope this solves your problem.

+2


source







All Articles