Logging JavaScript Errors To ASP.NET

It always a good practice to log all kind of exceptions raised on server size to keep track of issues. But what about JavaScript errors occurred at client side? With no proper implementation to log client side errors happening on browser, we are, IMO, loosing great amount of debugging information. Having those client side errors readily available to the developers,  it can cut major replicating and testing effort. Here is a superb library I found which can log JavaScript errors occurred at client side to the event log.

Links:
JavaScript Logger: Logging JavaScript Errors To ASP.NET
Download (DLL & Source Code): ClientLogger.ZIP

JavaScript exception logger has three components:

1. Script at client side which will catch Javascript exception using onerror event of window and notify server using AJAX mechanism. There will be no PostBack for passing exception to server.
2. HttpHandler on server which will receives the exception notification and passes it to EventLogger.
3. EventLogger which converts passed exception into string and log it into the EventLog.

Exception information which logged into EventLog by default are:

1. Actual JavaScript error message
2. JavaScript URL
3. Line number where exception has occurred.
4. Page URL
5. User Agent
6. Session ID

You can further enhance the ClientLoggerHandler class, if you want to log more browser/OS specific information. With that, as most developers always prefer, you can also log exception in database, you just need to modify WebJavaScriptErrorEvent.

To enable JavaScript logging, you just require drop a Logger control on the page (or on Master Page) and register HttpHandler.

Note: This library has been developed using ASP.NET 2.0, but I am sure it can be easily used in ASP.NET 1.1 as well with small modifications.

Happy Logging!