Step 1. Create a Model
to register the shares
namespace SeuProjeto.Models
{
public class ActionsLog
{
[Key]
public Guid ActionsLogId { get; set; }
public String Controller { get; set; }
public String Action { get; set; }
public String Ip { get; set; }
public DateTime DateAndTime { get; set; }
// Coloque aqui os campos extras que deseja usar para o registro
}
}
Step 2. Implement a Filter derived from ActionFilter
namespace SeuProjeto.Filters
{
public class CustomActionFilter : ActionFilterAttribute, IActionFilter
{
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
{
// Coloque aqui algumas regras de negócio que quiser antes de fazer o log.
// Aqui é o registro propriamente dito
var contexto = new MeuProjetoContext();
var log = new ActionsLog()
{
ActionsLogId = Guid.NewGuid(),
Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
Action = filterContext.ActionDescriptor.ActionName + " (Logged By: Custom Action Filter)",
Ip = filterContext.HttpContext.Request.UserHostAddress,
DateAndTime = filterContext.HttpContext.Timestamp
// Coloque aqui os campos extras para inclusão
};
contexto.ActionsLogs.Add(log);
contexto.SaveChanges();
this.OnActionExecuting(filterContext);
}
}
}
Step 3. Register your ActionFilter
in the Controller
desired
[CustomActionFilter]
public class MeuController : Controller
{
...
}
Or decorate the Actions
individually
[CustomActionFilter]
public ActionResult Index()
{
...
}
[CustomActionFilter]
public ActionResult Search(string term)
{
...
}
Well there’s this link:
http://msdn.microsoft.com/pt-br/library/dn630210.aspx
would be the basis of your question !!!– user6026