Elmah Error Logging with MongoDB Official Driver

This basically takes the work that Pablo M. Cibraro did to use Elmah with the Samus CSharp Driver and converts it to work with the Official 10Gen CSharp Driver instead plus a few additional minor changes:

  1. A capped collection is still used but the maximum size (in bytes) and the document limit can now be set using the ‘maxDocuments’ and ‘maxSize’ parameters in the configuration. By default the limit is based on size only with 100mb allocated.
  2. The paged-results for the Elmah reporting page are sorted in descending order so the latest errors are shown first. This uses the $natural sort order of the capped collection.
  3. I’ve used the native MongoDB ObjectId for the error id which should be slightly faster that using a Guid and sorts better (also, if you were interested in saving a few bytes this stores the date and time too so could avoid saving it separately).
  4. Finally, I’ve use the convention of calling the collection ‘Elmah’ when there is no ApplicationName set and ‘Elmah-ApplicationName’ when it is.

Configuration is very similar (but uses the 10Gen driver connection string format):

<elmah>
    <errorLog type="Elmah.MongoErrorLog, Elmah.MongoDB" connectionStringName="ELMAH.MongoDB" maxSize="10485760" maxDocuments="10000" />
</elmah>
<connectionStrings>
    <add name="ELMAH.MongoDB" connectionString="server=localhost;database=elmah;"/>
</connectionStrings>

The source code and compiled binaries are attached. I’ll look at submitting this to the Elmah codebase.

Thanks again to Pablo for doing the hard work !

About these ads

7 thoughts on “Elmah Error Logging with MongoDB Official Driver

  1. Pingback: « MongoDB provider for Elmah

  2. > I’ll look at submitting this to the Elmah codebase.

    Pablo has contributed[2] his initial implementation to the ELMAH Sandbox[1]. I’ve also applied some minor fixes and refactorings. It would be great to see your enhancements find their way in through a clone as well. As for which driver to use and how to proceed, perhaps this is something Pablo and you can collaborate on?

    [1] http://code.google.com/p/elmah-sandbox/
    [2] http://code.google.com/r/cibrax-mongodb/source/browse
    [3] http://code.google.com/p/elmah-sandbox/source/list

    • Sure, sounds good – I was planning on getting in touch to see where I should put it which ideally will be with the Elmah codebase.

      I was using the official driver in other parts of my app which is why I created a different version. Another option would be to ILMerge the driver so the specific one used doesn’t matter so much. I’ll get in touch with Pablo and see what he thinks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s