예제 #1
0
 private void WriteOpsLog(dynamic logInfo)
 {
     try
     {
         var properties = _mqProducer.CreateBasicProperties();
         //设置消息持久化
         properties.Persistent = true;
         _mqProducer.BasicPublish(BaseMqExchanges.Logs, BaseMqRoutingKeys.OpsLog, logInfo, properties);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message, ex);
     }
 }
예제 #2
0
        public void Intercept(IInvocation invocation)
        {
            invocation.Proceed();

            var serviceMethod = invocation.Method ?? invocation.MethodInvocationTarget;
            var attribute     = serviceMethod.GetCustomAttribute <OpsLogAttribute>();

            if (attribute == null)
            {
                return;
            }

            if (_isLoging)
            {
                return;
            }
            else
            {
                _isLoging = true;
            }

            var logInfo = new
            {
                ClassName       = serviceMethod.DeclaringType.FullName,
                CreateTime      = DateTime.Now,
                LogName         = attribute.LogName,
                LogType         = "操作日志",
                Message         = JsonSerializer.Serialize(invocation.Arguments),
                Method          = serviceMethod.Name,
                Succeed         = "",
                UserId          = _userContext.ID,
                UserName        = _userContext.Name,
                Account         = _userContext.Account,
                RemoteIpAddress = _userContext.RemoteIpAddress
            };


            var properties = _mqProducer.CreateBasicProperties();

            //设置消息持久化
            properties.Persistent = true;
            _mqProducer.BasicPublish(BaseMqExchanges.Logs, BaseMqRoutingKeys.OpsLog, logInfo, properties);
        }