【发布时间】:2012-10-17 16:10:37
【问题描述】:
我正在实现一个记录器,该记录器应通过操作过滤器捕获详细信息,以便记录用户活动和查找故障。
public interface ISessionLogger
{
void LogUserActionSummary(int sessionId, string userActionType);
void LogUserActionDetail(int session, string userActionType, DateTime userActionStartedUtc, long actionDurationInMilliseconds, string queryParams, string referredFrom);
}
我希望queryParams 捕获表单集合、路由值、操作参数、json 调用和查询字符串中的所有键和值,这听起来像是我需要的
filterContext.Controller.ValueProvider
但似乎不可能循环通过它。所以在我的 FilterAttribute 我有
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var paramList = new List<string>();
if(filterContext.ActionParameters != null)
{
paramList.AddRange(filterContext.ActionParameters.Select(param => String.Format("{0}:{1}", param.Key, param.Value.ToString())));
}
if(filterContext.Controller.ValueProvider != null)
{
//loop through the valueprovider and save the key value pairs to paramList
}
_queryParams = string.Join(",", paramList);
}
还有其他方法可以在动作过滤器的 OnActionExecuting 方法中实现吗?
【问题讨论】:
-
您是否查看了 MSDN 以了解有关 ValueProvider 的更多详细信息? - msdn.microsoft.com/en-us/library/…
标签: c# asp.net-mvc-3 logging action-filter