views:

393

answers:

5

Everyone probably notices that most modern applications nowadays has a way for user to send crash/bug report either automatically or with user permission. Some examples are Mozilla Crash Reporter or most Microsoft applications.

I really like this feature since it allows me to collect the bugs report quickly with helpful information than just let my user reports the bug/issue traditionally such as submit a help ticket.

I wonder if there is an easy or systematic way to implement that capability in ASP.NET web application.

Have you guys had any experience or knowledge to share for both WebForms and MVC applications? Or if this could be implemented in Client-side like JavaScript/JQuery, that'd be good.

Thanks!

+1  A: 

For an ASP.NET applicatino--or any Web application for that matter--isn't this just a two-step process of:

  1. Logging the error (obviously); and
  2. Put a form on the error document to allow the user to enter feedback.

Or is there more to this?

cletus
Thanks. That's true. However, I was looking for a library or framework (built-in or not), so that I could use it easily with ASP.NET application.
kimsk
+2  A: 

ELMAH is a library that plugs in and detects exceptions. You can also log an event yourself. The events and a great deal of data like url parameters and browser information can be emailed to administrators and optionally stored in a database for display. (Rather like an event log for the web site.) It doesn't have a built-in user form that I've seen, but can probably be extended to include such an option.

I've been using/customizing it for about two years now and it is really exceptional.

Another option might be to use Kampyle which includes a feedback box on the bottom right of your web site. You could use Javascript to trigger the box to appear if an issue is detected on the web site.

DavGarcia
Thanks for your answer. Those tools could be helpful for my projects too.
kimsk
+1  A: 

Your errors will pass through the Application_Error method of the Global.asax.cs file (which you may have to create). I use this fact to capture the error and log it to a database:

void Application_Error(object sender, EventArgs e)
{
    try
    {
        SqlConnection errConnection = new SqlConnection("Your connection string");

        // After setting up a command object, I call a stored procedure to save information about
        // the crash.  I pass two primary arguments.  The first is the URL:
        errCommand.Parameters.Add("@URL", SqlDbType.VarChar).Value = Request.Url.ToString();

        // The second is the error information.
        errCommand.Parameters.Add("@EI", SqlDbType.Text).Value = Server.GetLastError().ToString();

        // I pass some other information from my session as well...

       // After setting up an output parameter called ErrorID, I call the command...
       errCommand.ExecuteNonQuery();
       // Now Error ID is stored in the session.
       Session["ErrorID"] = (int)ErrorID.Value;
    }
    catch { } //  I do NOT want the error handling call to throw an error.
}

Now, you should have set up your Web.Config file so that a specific page gains control when an error occurs. In this page, you'll check the session for the error ID and show it to the user. In the output, I ask the user to write down the error if they would like to call us for more information. If we do receive a request, I can go into the database and get a complete trace of the error.

Mark Brittingham
+1  A: 

You can checkout my tutorial on how to implement exception logging in asp.net - http://jesal.us/blog/index.php/2008/04/08/exception-logging-using-the-database/

jesal
+6  A: 

ASP.NET 2.0 introducted Health monitoring, which allows you to do this by just adding some stuff to the web.config. See: http://msdn.microsoft.com/en-us/library/ms998306.aspx

It can log to mail, sql, eventlog, etc. and allows you to set buffers. So it for example won't kill your mailserver if the sql database goes down or if some user discovers a bug and tries to call it too often a second :-)

You can also log failed authentication and app pool restarts with it, it's pretty usefull if you just need it working quick. It's still questionnable if it is the best solution to manage all the errors. Because it might not got all the information you need, for example browser version or smt like that.

erik
+1 For a very useful answer. I answered below with some software that I built to do this back in the ASP.NET 1.0 days but you've got me thinking I may need to take another approach. Thanks!
Mark Brittingham
Thanks for the tips. Your answer leads me to find the useful link of how to use Health monitoring with MVC. http://www.alexthissen.nl/blogs/main/archive/2008/07/01/health-monitoring-action-filter-for-asp-net-mvc.aspx
kimsk