Using Common.Logging with Glimpse and ASP.Net MVC

Glimpse is an amazing tool (that comes available with Nuget in Visual Studio 2010 [included in the Tools Update]) that can hook into the System.Diagnostic.Trace (ewww) to display error messages on your client side browser. Like so:

image

I don’t want to use System.Diagnostics as my Logging system. I could use it on the side, but not as the core. This would be awful and much too rigid. The good thing is, I typically use Common.Logging in all my projects because of it’s way to tie ANY LOGGING SYSTEM into a single point then ship those events off to any other receiving system. The receiving system in this case, is  of course, System.Diagnostics.Trace using the TraceLoggerFactoryAdapter

So to get to the point above this is what I did:

  1. Using Create a new MVC project in VS2010
  2. Nuget
    1. Install-Package Glimpse
    2. Install-Package Common.Logging
  3. Add Common.Logging  to the web config
    <!--...config sections... --> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> </sectionGroup> <!--...configuration... --> <common> <logging> <factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e"> <arg key="level" value="ALL" /> <arg key="showLogName" value="true" /> <arg key="showDataTime" value="true" /> <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" /> </factoryAdapter> </logging> </common>

  4. Add some “problems”image
  5. Run the project and go to http://[your project url]/Gimpse/Configthen click “Turn Glimpse On”. Don’t be surprised that nothing happens.

    image

  6. Go to your main page http://[your project url]/ – See the icon in the right hand corner? Click that.
    image
  7. Look at those errors!

image

Conclusion?

Amazing! The guys who made Glimpse deserve some sort of medal!

This entry was posted in ASP.Net and tagged , , , . Bookmark the permalink.

3 Responses to Using Common.Logging with Glimpse and ASP.Net MVC

  1. Pingback: ASP.Net MVC 3 Project Setup (with Glimpse, ELMAH & MiniProfiler)

  2. Uys says:

    I am more of a front end developer with inrmteediate experience on the back end, so please forgive my inability to answer these questions on my own:Could you provide an example or two where this would be useful? Maybe you could discuss the pros and cons of this as opposed to web services or update panels. Would this work with forms? thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>