Logging and Handling Exceptions: ActionFilters or Global.asax ??

Last post 11-09-2009 6:16 AM by guillermoguerini. 4 replies.

Sort Posts:

  • Logging and Handling Exceptions: ActionFilters or Global.asax ??

    11-08-2009, 1:32 PM

    Hello mates,

    I've been studying about logging and exceptions handlers and I found two different approaches:

    1) Create a ActionFilter to handle the exceptions and log the messages to a file for example.
    You can read more about it here
     - http://ludwigstuyck.wordpress.com/2009/06/15/asp-net-mvc-quickstart-7-action-filters/
     -  http://www.dimecasts.net/Casts/CastDetails/37

    2) Using the Global.asax (on error) to log the errors. You can find more info here:
     - http://www.asp.net/LEARN/mvc-videos/video-430.aspx


    The question is which one is the best approach? I like the ActionFilters because I might have more control. Also I was thinking about putting both approaches together (using ActionFilters with the NLog.net).

    What do you recommend guys?

    Thanks for that.

    Guillermo Guerini
    http://gguerini.com
  • Re: Logging and Handling Exceptions: ActionFilters or Global.asax ??

    11-08-2009, 2:46 PM
    • Contributor
      5,500 point Contributor
    • sukumarraju
    • Member since 06-14-2006, 10:01 PM
    • Scotland, UK
    • Posts 1,174

    Have you looked into Exception Handling and Logging applicaiton blocks from Enterprise Library?

    These application blocks are designed and developed by Microsoft patterns and practices team. With very little effort by configuring these blocks, you can implement best practices for Logging your exceptions.

     

    Let me know further Queries.

    Thanks,

     

    -- "Mark As Answer" if my reply helped you --
    Recommended Book
    Application Architecture Guide 2.0
    My Blog
  • Re: Logging and Handling Exceptions: ActionFilters or Global.asax ??

    11-08-2009, 2:56 PM

    I think I didn't explain myself very clear. About how to handle exceptions and log these exceptions is not the problems here. If I'll use the NLog or the MS Application Blocks, doesn't really matters now. But how to apply these things to my application. I've been reading a lot about the ActionFilters doing these things but I wasn't sure it's the best approach and this is what I'm looking for.

    So this is my question. 

    Thanks anyways.


    Guillermo Guerini
    http://gguerini.com
  • Re: Logging and Handling Exceptions: ActionFilters or Global.asax ??

    11-08-2009, 4:39 PM
    Answer
    • Contributor
      6,387 point Contributor
    • Augi
    • Member since 10-18-2008, 9:46 AM
    • Czech Republic
    • Posts 1,102

    I would definitelly use action filter for error handling. But I would implement Application_Error style handling too - because it's fallback when action filter based error handling fails (in case of some critical error).

    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: Logging and Handling Exceptions: ActionFilters or Global.asax ??

    11-09-2009, 6:16 AM

    Great.. this is what I wanted to hear. I think it's a good idea to do both things to prevent any kind of serious breakdown. ;)


    Thanks

    G

    Guillermo Guerini
    http://gguerini.com
Page 1 of 1 (5 items)