ELMAH + SignalR = ElmahR

Tagged: c# elmah signalr elmahr

During the last few days I've been working on a new idea. I've been listening and reading about SignalR since a few months, and 2 weeks ago I attended a very interesting session by Marteen Balliauw about it at the UGIALT.NET conference in Milan. At the same time I'm an ELMAH user since a while, and I have the pleasure to share my working hours and my lunches with its author Atif. So, when I was in my car coming back from the conference to where I live, and despite (or maybe thanks to...) a bad cold that was hitting me, I had this idea to join these two libraries to offer real time and interactive experience to the logging capabilities that ELMAH offers. This week I started this experiment and I had a lot of fun working on it.

First, I cloned the ELMAH Sandbox project repository following the recommended guidelines, and inside it I wrote a new ErrorPostModule for ELMAH. This module is very simple, and so far its implementation is still very basic, its goal is to process an unhandled exception that occurred in the host application and post its Json representation to a specified destination. When you have this module available, in your ELMAH-enable applications you can activate it adding a configuration key like this one:

<configuration>
  <configSections>
    <sectionGroup name="elmah">
      ...
      <section 
        name="errorPost" 
        requirePermission="false" 
        type="Elmah.ErrorLogSectionHandler, Elmah"/>
    </sectionGroup>
  </configSections>
  ...
  <elmah>
    ...
    <errorPost
      url="http://localhost:51526/posterror.ashx"
      applicationName="Wasp is doing ElmahR"
      handshakeToken="Strawberry fields forever" />
  </elmah>
  ...
  <system.web>
    ...
    <httpModules>
      ...
      <add 
        name="ErrorPost"  
        type="Elmah.Sandbox.ErrorPostModule, Elmah.Sandbox" />
    </httpModules>
    ...
  </system.web>
</configuration>

Just as simple as that. The only notable thing is this 'handshake token' that must be specified to uniquely identify the source application, so that the destination application can enable it and add it to the list of the monitored sources. Please note that this is still experimental, ok? :) And please note also that this module has no dependency at all on SignalR, it's just doing a plain old HTTP POST following some conventions about how to pack data.

After that I moved to the SignalR side. The idea is that we have a monitoring application which shows errors occurring in monitored web sites in real time. If you want you can configure things to have the same application running both the monitoring and monitored roles. So:

  • I wrote a SignalR hub which easily enables the client-server communication
  • I introduced and .ashx handler where errors are posted and unpacked thanks to the same conventions used on the ELMAH side
  • I added some draft features to store received errors in order to enable the application to notify new clients about older exceptions,
  • I wrote a basic sample page where you can see the errors popping up in real time, thanks to the javascript client-side features from SignalR.

The result is quite interesting, and it's been really easy to achieve it. I pushed it alll online, and it's been already pulled in the main sandbox repository. ElmahR was born :)

The next steps? I want to consolidate the general idea to define the direction this thing might take, but there are a lot of opportunities thanks to the great features and modularity that both ELMAH and SignalR offer. It should be quite straightforward to build some sort of pluggable mechanism allowing people to create monitoring dashboards where they can keep multiple runnning application under real time control, reacting promptly to errors and possibly offering live assistance to the user that experienced the problem.

4 Comments

Add a Comment