Click here to Skip to main content
15,903,362 members
Articles / Web Development / ASP.NET
Article

Log server-side and client-side errors automatically

Rate me:
Please Sign up or sign in to vote.
2.00/5 (2 votes)
1 Oct 2008CPOL3 min read 20.4K   11   4
This article focuses on how to log all errors your end-users get (and you never know about!) automatically

Introduction 

This article focuses on how to log all errors your end-users get (and you never know about!) automatically and making it available in a single hosted service account:

Background  

We are ASP.NET developers working on many sites, growing sick and tired of the whole error reporting, bugtracking and fixing loop that we are sucked into daily. And it never gets better. You never know if what you fixed is really fixed for all clients. Your QA guys go over the same issue again and again and verify it, but miss to test in on that specific Mac OSX Safari browser that 10% of your end-users are using. 

So what is the solution? Is there a way to automate this whole mess in just 10 minutes? 

The Solution

The idea is really simple. ASP.NET is a great framework and allows developers to hook custom modules into their web sites and project. One such module can intercept all errors your application encounters in a generic way. So why not just install this module and have it automatically log all errors somewhere? 

Sure, this idea is not new and there are some tools that help here, but say you have 5 sites you want to monitor? Or you want to be notified only about certain errors and not for other via email or RSS? Or how about that - you want to log client side javascript errors as well?  All of this conveniently stored in a single place, in a hosted service?

How it works 

Very simple really. We created a new site for this service  http://www.spacebin.net where we decided we will keep track of all errors our own sites get. We also created a free account plan so that anyone else can test and use it and give us feedback (so please do).

The we created the SpaceBin.ErrorLogging module, which you can find attached to this article. Installation is very simple

  • Sign-up for a free account on our site www.spacebin.net, login and create a new website to be monitored by your account. Creating a new website to be monitored generates an unique key for the site.
  • Download the Spacebin.ErrorLog ASP.NET module binary (Spacebin.ErrorLog.dll) from attached file or from the following link
  • Copy the Spacebin.ErrorLog.dll file to the /bin folder of your application.
  • Modify the web.config file of your website in the following way
    • Add a new section describing the new Spacebin.ErrorLog configuration tag (copy this literally)
      <configuration>
          <configSections>
              ...
              <section name="Spacebin.ErrorLog"
                          requirePermission="false"
                          type="System.Configuration.SingleTagSectionHandler,System,
                                  Version=1.0.3300.0,
                                  Culture=neutral,
                                  PublicKeyToken=b77a5c561934e089"/>
              ...
          </configSections>
      </configuration>
      
    • Add the <spacebin.errorlog> configuration and the key you have been given for the website you monitor and the Url to the service site. Example:
      <configuration>
          ...
          <Spacebin.ErrorLog key="9b68abbf3b3a04b4fcd6f91a4a2919e47bfb937e"
          crashServiceUrl="www.spacebin.net"
          enableErrorSending="true"/>
          ...
      </configuration>
      
      The properties in the configuration mean:

      key - the unique identification key for the website you wish to monitor.
      carshServiceUrl - the URL of the crash service webiste provided by Spacebin.
      enableErrorSending - can be used to temporarily stop loggin errors to your Spacebin account (you can switch it off when you upgrade/maintain your site and then back on in production mode). Default value is true.  
    • Modify the HttpModules section to map error messages to the Spacebin logger. Example:
      <configuration>
          ...
          <system.web>
              <httpModules>
                  ...
                      <add name="ErrorLog" type="Spacebin.ErrorLog.LogModule, Spacebin.ErrorLog"/>
                  ...
              </httpModules>
          </system.web>
      
  • Testing and verifying crash service works correctly.
    Just create a page that throws any kind of exception, anywhere. For example:
    protected void Page_Load(object sender, EventArgs e)
    {
        throw new Exception("Test Exception That Should be Logged");
    }
    
    Verify that this exception is logged in your account on our site. If this is not the case, please go through the checklist again and see if you have missed something. 


The End Result 

All server-side and client-side errors your end-users get and you never knew about in one convenient interface



The End Result

If you have any questions or comments - please comment here or send me an email to sven@spacebin.net

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Spacebin
United States United States
I am just like you - ASP.NET developer working on many sites, growing sick and tired of the whole error reporting, bugtracking and fixing loop that we are sucked into daily. And it never gets better. You never know if what you fixed is really fixed for all clients. Your QA guys go over the same issue again and again and verify it, but miss to test in on that specific Mac OSX Safari browser that 10% of your end-users are using.

What is the solution? Go to www.spacebin.net and you will find out.

Comments and Discussions

 
GeneralELMAH Pin
Todd Smith2-Oct-08 10:30
Todd Smith2-Oct-08 10:30 
GeneralNice idea but to be extended Pin
giammin2-Oct-08 3:35
giammin2-Oct-08 3:35 
GeneralRe: Nice idea but to be extended Pin
Sven Larson2-Oct-08 5:50
Sven Larson2-Oct-08 5:50 
GeneralRe: Nice idea but to be extended Pin
giammin2-Oct-08 12:13
giammin2-Oct-08 12:13 
if i go by browser to www.spacebin.net i see a web page with only this text:
spacebin.net

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.