C#操作日志
2021-07-04 19:09
标签:red module isa bsp 获取数据 cep decode inpu json C#操作日志 标签:red module isa bsp 获取数据 cep decode inpu json 原文地址:https://www.cnblogs.com/zengtianli/p/9844906.htmlpublic class OperationLogAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
var actionName = filterContext.ActionDescriptor.ActionName;
//检测是否登录控制器
var isAjaxRequest = filterContext.RequestContext.HttpContext.Request.IsAjaxRequest();
//页面加载
if (isAjaxRequest)
{
//过滤主页请求
if (filterContext.RequestContext.HttpContext.Request.RequestType.Equals("Post",
StringComparison.OrdinalIgnoreCase))
{
//获取数据去去掉
if (!controllerName.Equals("Login", StringComparison.OrdinalIgnoreCase)
&& !controllerName.Equals("ClientLogin", StringComparison.OrdinalIgnoreCase)
&& !controllerName.Equals("Leader", StringComparison.OrdinalIgnoreCase)
&& !controllerName.Equals("Home", StringComparison.OrdinalIgnoreCase)
&& !actionName.Equals("GetClientDataJson", StringComparison.OrdinalIgnoreCase))
{
//请求数据
filterContext.RequestContext.HttpContext.Request.InputStream.Position = 0;
var byts = new byte[filterContext.RequestContext.HttpContext.Request.InputStream.Length];
filterContext.RequestContext.HttpContext.Request.InputStream.Read(byts, 0, byts.Length);
var req = System.Text.Encoding.Default.GetString(byts);
//请求文本
req = filterContext.RequestContext.HttpContext.Server.UrlDecode(req);
//请求地址
var reqUrl = filterContext.RequestContext.HttpContext.Request
.AppRelativeCurrentExecutionFilePath;
//返回结果
var content = "";
if (filterContext.Result != null)
{
content = "执行成功";
}
else
{
content = filterContext.Exception.Message + "," + filterContext.Exception.Source;
}
//获得用户信息
var opr = OperatorProvider.Provider.Current();
var f_modelid = SystemInfo.CurrentModuleId;
var f_module = new ModuleBLL().GetEntity(f_modelid).F_FullName;
var f_executeResult = filterContext.Exception == null ? 1 : 0;
//异步执行保存
Task.Factory.StartNew(() =>
{
#region 构造日志实体
LogEntity logEntity = new LogEntity();
logEntity.F_CategoryId = 3;
logEntity.F_OperateTypeId = ((int)OperationType.Submit).ToString();
logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Submit);
logEntity.F_ExecuteResult = f_executeResult;
logEntity.F_OperateAccount = opr.Account;
logEntity.F_OperateUserId = opr.UserId;
logEntity.F_ExecuteResultJson = string.Format("执行结果:{0}",content);
logEntity.F_ModuleId = f_modelid;
logEntity.F_Module = f_module;
logEntity.F_Description = string.Format("执行操作:{0},请求:{{{1}}}", reqUrl, req);
#endregion
try
{
logEntity.WriteLog();
}
catch (Exception e)
{
// ignored
}
});
}
}
}
base.OnActionExecuted(filterContext);
}
}