Files
MileageTraker/Web/Utility/ActionLogAttribute.cs
T
2012-11-30 21:35:06 -05:00

24 lines
836 B
C#

using System.Linq;
using System.Web.Mvc;
namespace MileageTraker.Web.Utility
{
public class ActionLogAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext != null)
{
string controller = filterContext.RouteData.Values["controller"].ToString();
string action = filterContext.RouteData.Values["action"].ToString();
string loggerName = string.Format("{0}Controller.{1}", controller, action);
string @params = string.Join(", ", filterContext.ActionParameters.Select(i => i.Key + ": " + i.Value));
string hostAddress = "UserHostAddress: " + filterContext.HttpContext.Request.UserHostAddress;
log4net.LogManager.GetLogger(loggerName).Info(hostAddress + ", " + @params);
}
base.OnActionExecuting(filterContext);
}
}
}