• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/NjIy

Related Code
Fork of GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Get Cookies in Web Api Asp .net Mvc 4 RC
GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Using DynamicObject to get a value from the Request.Params
PagedList class and paging code for ASP.Net MVC (Nothing new but kind of usefull.)
Removing properties from the model state the typed way in ASP.NET MVC
A simple way to cache slow functions in C#
Fork of Serialize an object into a Querystring, using LINQ syntax
Serialize an object into a Querystring
HttpContextLifetimeManager for Unity

ActionFilter to Handle and Log Error for each Controller, ASP.NET MVC

ActionFilter to handle and log exception in ASP.Net MVC 3.0

1
1.1k 0 0 0 0 0

using System.Text;
using System.Web.Mvc;
using Infrastructure.Log;

namespace Infrastructure.ActionFilters
{
   public class HandleErrorAndLogExceptionFilter : HandleErrorAttribute
   {
       private readonly ILogManager _logger;

       public HandleErrorAndLogExceptionFilter(ILogManager logger)
       {
           _logger = logger;
       }

       public override void  OnException(ExceptionContext filterContext)
       {
          base.OnException(filterContext);

           var url = filterContext.HttpContext.Request.Path;
           var error = filterContext.Exception;

           var text = new StringBuilder("Error occurred at ");
           text.Append(url);
           text.AppendLine(" With error: ");
           text.AppendLine(error.ToString());

           _logger.Error(text);
       }
    }
}

The ActionFilter is registred for all Controllers in the Global.asax:

public void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    ...
    filters.Add(new HandleErrorAndLogExceptionFilter(new MyLogger()));
}

Share: twitter | facebook   Action: used | fork | flag

asp.net

Mark 'asp.net' tag as 'like'

Mark 'asp.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

exception

Mark 'exception' tag as 'like'

Mark 'exception' tag as 'ignore'

logging

Mark 'logging' tag as 'like'

Mark 'logging' tag as 'ignore'

mvc

Mark 'mvc' tag as 'like'

Mark 'mvc' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
March 21, 2011 3:45 PM
edited March 24, 2011 9:55 PM

Fork

 ActionFilter to Handle and Log Error for each Controller, ASP.NET MVC -  @fredrikn Monday 21, 2011 3:45 PM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010