{
LogMessage(filterContext.RouteData.Values["controller"].ToString(),
filterContext.RouteData.Values["action"].ToString(),
"Action exeuting...");
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
LogMessage(filterContext.RouteData.Values["controller"].ToString(),
filterContext.RouteData.Values["action"].ToString(),
"Action executed.");
}
public void OnResultExecuting(ResultExecutingContext filterContext)
{
LogMessage(filterContext.RouteData.Values["controller"].ToString(),
filterContext.RouteData.Values["action"].ToString(),
"Result executing...");
}
public void OnResultExecuted(ResultExecutedContext filterContext)
{
LogMessage(filterContext.RouteData.Values["controller"].ToString(),
filterContext.RouteData.Values["action"].ToString(),
"Result executed");
}
}
自定义好LogMessageAttribute类
,应用到Controller或者action的属性
。在Controller 正在执行
,或者呈现一个View,一个HTTP请求数据时,就会在日志文件记录一些日志.
在项目的Controller里面应用自定义的属性
[Logging(LogName = @"D:ProjectProjectMVCProjectsky.ExtendMVCFrameworksky.ExtendMVCFrameworkLog.log")]
public ActionResult DesplayEmployee()
{
ViewData["Message"] = "Our employees welcome you to our site!";
List<Employee> employees = new List<Employee>
{
new Employee
{
FirstName="sky",
LastName="yang",
Email = "weflytotti@163.com",
Department ="Development"
},
new Employee {
FirstName="sky",
LastName="yang",
Email = "weflytotti@163.com",
Department ="Development"
}
};
return View(employees);
}
运行程序,正如文章开始所看到的截图!