/// <summary>
        ///     Action开始执行触发
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            _operationLogHandler = new OperationLogHandler(filterContext.HttpContext.Request);
            CurrentUser          = AuthenticationExtension.Current();
            if (CurrentUser != null)
            {
                _operationLogHandler.log.CreateUserCode = CurrentUser.Code;
                _operationLogHandler.log.CreateUserName = CurrentUser.Name;
            }

            //获取Action特性
            var descriptionAttribute = filterContext.ActionDescriptor.EndpointMetadata.Where(a => a is DescriptionAttribute).ToList();;

            if (descriptionAttribute.Any())
            {
                var info = descriptionAttribute[0] as DescriptionAttribute;
                if (info != null)
                {
                    var description = info.Description;
                    _operationLogHandler.log.ControllerName =
                        ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)filterContext.ActionDescriptor).ControllerName;
                    _operationLogHandler.log.ActionName = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)filterContext.ActionDescriptor).ActionName;
                    _operationLogHandler.log.Describe   = description;
                }
            }

            base.OnActionExecuting(filterContext);
        }
Example #2
0
        /// <summary>
        /// 开始执行
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            var request = context.HttpContext.Request;

            _operationLogHandler = new OperationLogHandler(_accessor, request, _currentUser)
            {
                Log =
                {
                    ControllerName = ((ControllerActionDescriptor)context.ActionDescriptor).ControllerName,
                    ActionName     = ((ControllerActionDescriptor)context.ActionDescriptor).ActionName
                }
            };
            var descriptionAttribute = context.ActionDescriptor.FilterDescriptors;

            if (!descriptionAttribute.Any())
            {
                return;
            }
            foreach (var attr in descriptionAttribute)
            {
                var info = attr.Filter.ToString();
                if (info == "EIP.Common.Restful.Attribute.RemarkAttribute")
                {
                    _operationLogHandler.Log.Describe = ((RemarkAttribute)attr.Filter).Describe;
                }
            }
        }
Example #3
0
        public void WriteTrace_works()
        {
            string result  = null;
            var    handler = new OperationLogHandler(writeTrace: m => result = m);
            var    message = "Princess Celestia is an alicorn.";

            handler.WriteTrace(message);

            Assert.Equal(message, result);
        }
Example #4
0
        public void WriteDebug_works()
        {
            string result  = null;
            var    handler = new OperationLogHandler(writeDebug: m => result = m);
            var    message = "Princess Celestia is a princess.";

            handler.WriteDebug(message);

            Assert.Equal(message, result);
        }
Example #5
0
        public void WriteInformation_works()
        {
            string result  = null;
            var    handler = new OperationLogHandler(writeInformation: m => result = m);
            var    message = "Princess Celestia is on her way.";

            handler.WriteInformation(message);

            Assert.Equal(message, result);
        }
Example #6
0
        public void WriteError_works()
        {
            string result  = null;
            var    handler = new OperationLogHandler(writeError: m => result = m);
            var    message = "Princess Celestia does not exist.";

            handler.WriteError(message);

            Assert.Equal(message, result);
        }
Example #7
0
        public void Write_methods_are_noops_when_null()
        {
            var handler = new OperationLogHandler();

            handler.WriteError("Princess Celestia does not exist.");
            handler.WriteWarning("Princess Celestia is in danger.");
            handler.WriteInformation("Princess Celestia is on her way.");
            handler.WriteDebug("Princess Celestia is a princess.");
            handler.WriteTrace("Princess Celestia is an alicorn.");
        }
Example #8
0
 /// <summary>
 ///     重写Controller,此处可写入登录日志
 /// </summary>
 /// <param name="requestContext">上下文对象</param>
 protected override void Initialize(RequestContext requestContext)
 {
     base.Initialize(requestContext);
     //从Cookie里面获取用户信息
     CurrentUser = FormAuthenticationExtension.Current(SystemWeb.HttpContext.Current.Request);
     if (CurrentUser != null)
     {
         _operationLogHandler = new OperationLogHandler(Request)
         {
             log =
             {
                 CreateUserCode = CurrentUser.Code,
                 CreateUserName = CurrentUser.Name
             }
         };
     }
 }