Inheritance: HandlerAttribute
Example #1
0
        static void Main(string[] args)
        {
            string          path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).ToString() + "\\AwesomeIgor.exe";
            LoggerAttribute afl  = new LoggerAttribute("");

            afl.InjectToAssembly(path);
        }
Example #2
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            //当方法或控制器上存在DisableAuditingAttribute特性标签时,不记录日志
            if (context.ActionDescriptor is ControllerActionDescriptor d && d.MethodInfo.IsDefined(typeof(DisableAuditingAttribute), true) ||
                context.Controller.GetType().IsDefined(typeof(DisableAuditingAttribute), true)
                )
            {
                base.OnActionExecuted(context);
                return;
            }
            LoggerAttribute loggerAttribute = context.ActionDescriptor.EndpointMetadata.OfType <LoggerAttribute>().FirstOrDefault();
            var             linLog          = new LinLog
            {
                Path       = context.HttpContext.Request.Path,
                Method     = context.HttpContext.Request.Method,
                StatusCode = context.HttpContext.Response.StatusCode,
                UserId     = _currentUser.Id ?? 0,
                Username   = _currentUser.UserName
            };

            if (loggerAttribute != null)
            {
                linLog.Message = this.parseTemplate(loggerAttribute.Template, _currentUser, context.HttpContext.Request, context.HttpContext.Response);
            }
            else
            {
                linLog.Message = $"访问{linLog.Path}";
            }

            LinCmsAuthorizeAttribute linCmsAttribute = context.ActionDescriptor.EndpointMetadata.OfType <LinCmsAuthorizeAttribute>().FirstOrDefault();

            if (linCmsAttribute != null)
            {
                linLog.Authority = $"{linCmsAttribute.Module}  {linCmsAttribute.Permission}";
            }

            _logRepository.Insert(linLog);
            base.OnActionExecuted(context);
        }
Example #3
0
        static void LoggerSet(LoggerValueMode canValue, LoggerAttribute argLogAttr, System.Collections.Generic.Dictionary <string, dynamic> logObjs, string name, dynamic value)
        {
            switch (canValue)
            {
            case LoggerValueMode.All:
                if (null != argLogAttr && !argLogAttr.CanWrite)
                {
                    break;
                }
                logObjs.Add(name, value);
                break;

            case LoggerValueMode.Select:
                if (null != argLogAttr && argLogAttr.CanWrite)
                {
                    logObjs.Add(name, value);
                }
                break;

            default: break;
            }
        }
Example #4
0
    public void Add(Type klass)
    {
        List <MemberData> res = new List <MemberData>();

        object[] attrs = klass.GetCustomAttributes(typeof(LoggerAttribute), false);
        foreach (object o in attrs)
        {
            LoggerAttribute l = (LoggerAttribute)o;
            if (l.LogMember.Equals(LogEnum.Properties))
            {
                LoadProperties(klass, res);
            }
            else if (l.LogMember.Equals(LogEnum.Fields))
            {
                LoadFields(klass, res);
            }
            else if (l.LogMember.Equals(LogEnum.Methods))
            {
                LoadMethods(klass, res);
            }
        }
        members.Add(klass, res.ToArray());
    }