24 lines
821 B
C#
24 lines
821 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)
|
|
{
|
|
var controller = filterContext.RouteData.Values["controller"].ToString();
|
|
var action = filterContext.RouteData.Values["action"].ToString();
|
|
var loggerName = string.Format("{0}Controller.{1}", controller, action);
|
|
var @params = string.Join(", ", filterContext.ActionParameters.Select(i => i.Key + ": " + i.Value));
|
|
|
|
var hostAddress = "UserHostAddress: " + filterContext.HttpContext.Request.UserHostAddress;
|
|
|
|
log4net.LogManager.GetLogger(loggerName).Info(hostAddress + ", " + @params);
|
|
}
|
|
base.OnActionExecuting(filterContext);
|
|
}
|
|
}
|
|
} |