public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            try
            {
                //操作类型(0新增 1修改 2删除 3登录)
                WebSysLog log  = new WebSysLog();
                var       info = SysLoginInfo.CurAccount();
                if (info != null)
                {
                    log.ManagerGuid    = info.ManagerId.ToString();
                    log.ManagerAccount = info.ManagerName;
                }
                log.LogIp   = GetIP();
                log.LogType = _type;
                log.LogTime = DateTime.Now;//操作时间
                log.LogName = _LogTypeName;

                string control = filterContext.Controller.ValueProvider.GetValue("controller").AttemptedValue;
                string action  = filterContext.Controller.ValueProvider.GetValue("action").AttemptedValue;

                //参数说明
                StringBuilder ParamContent = new StringBuilder();
                if (_parameterNameList != "")
                {//根据条件得到参数
                    ParamContent.Append(GetWhereParam(filterContext.Controller.ValueProvider));
                }
                else
                {//获取提交的所有参数
                    ParamContent.Append(GetAllParam(filterContext.Controller.ValueProvider));
                }
                log.MapMethod  = control + "/" + action;  //操作方法
                log.LogContent = ParamContent.ToString(); //参数说明

                //根据数据表设计,进行字符串的裁剪
                log.LogContent = log.LogContent.Length > 4000 ? log.LogContent.Substring(0, 4000) : log.LogContent;
                log.MapMethod  = log.MapMethod.Length > 100 ? log.MapMethod.Substring(0, 100) : log.MapMethod;

                web_managerEntities db = new web_managerEntities(Encrypt.StringDecodeOne(DBConfigure.ConnStr));
                db.WebSysLog.Add(log);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog("写操作日志错误", ex);
            }
        }
Example #2
0
        public void Add(long uid, string name, string ip, int type, string typename, string mapmethod, string logcontent)
        {
            WebSysLog log = new WebSysLog();

            log.ManagerGuid    = uid.ToString();
            log.ManagerAccount = name;
            log.LogIp          = ip;
            log.LogType        = type;
            log.LogTime        = DateTime.Now; //操作时间
            log.LogName        = typename;
            log.MapMethod      = mapmethod;    //操作方法
            log.LogContent     = logcontent;   //参数说明

            //根据数据表设计,进行字符串的裁剪
            log.LogContent = log.LogContent.Length > 4000 ? log.LogContent.Substring(0, 4000) : log.LogContent;
            log.MapMethod  = log.MapMethod.Length > 100 ? log.MapMethod.Substring(0, 100) : log.MapMethod;

            db.WebSysLog.Add(log);
            db.SaveChanges();
        }