18 May 2006

Logging JavaScript Errors To ASP.NET

No Comments ASP.NET

We always log all kind of exceptions raise at server side to keep track of all those bugs. But what about JavaScript errors occurred at client side? I think we are simply loosing great amount of debugging information by not logging these JavaScript errors, which IMO can surly help developers to cut replicating and testing effort.

Here is the superb library which can log all JavaScript errors occurred at client side to event log.

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

The JavaScript exception logger is having three segments:
1. Script at client side which will catch Javascript exception using onerror event of window and notify server using AJAX mechanism. So there will be no PostBack for passing exception to server.
2. HttpHandler on server which will receives this exception notification and passes it to EventLogger.
3. EventLogger which converts passed exception into string and logs it in the EventLog

Exception information which logged into EventLog:
1. Actual JavaScript error message
2. JavaScript URL
3. Line number of the script where exception has been occurred.
4. Page URL
5. User Agent
6. Session ID

You can further enhance ClientLoggerHandler class, if you want to log any other browser/OS specific information. With that, as most developers always prefer to log exception in database, you can modify WebJavaScriptErrorEvent accordingly.

To enable JavaScript logging, you just need to 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 very small modification.

Happy Logging!!

written by Firoz Ansari
The author didn‘t add any Information to his profile yet.
No Responses to “Logging JavaScript Errors To ASP.NET”

Leave a Reply

Spam protection by WP Captcha-Free