コード例 #1
0
        /// <summary>
        /// 生成业务异常信息
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="queueMessage">队列消息</param>
        /// <param name="amqpQueue">AMQP队列信息</param>
        /// <param name="log">日志</param>
        /// <param name="desc">描述</param>
        /// <returns>业务异常信息</returns>
        public static BusinessExceptionInfo BuilderBusinessException(Exception ex, object queueMessage, AmqpQueueInfo amqpQueue, ILogable log, string desc = null)
        {
            if (log == null)
            {
                throw new ArgumentNullException("日志不能为null");
            }
            string queueMessageJson = null;

            if (queueMessage != null)
            {
                try
                {
                    queueMessageJson = queueMessage.ToJsonString();
                }
                catch (Exception ex1)
                {
                    log.ErrorAsync("JSON序列化业务异常信息出错", ex1, typeof(AmqpUtil).Name);

                    return(null);
                }
            }

            var busEx = new BusinessExceptionInfo()
            {
                ExId                   = snowflakeId.New(),
                HostId                 = amqpQueue.HostId,
                Time                   = DateTime.Now,
                ServiceName            = string.IsNullOrWhiteSpace(amqpQueue.ExceptionHandle.ServiceName) ? App.AppServiceName : amqpQueue.ExceptionHandle.ServiceName,
                ExceptionString        = ex.ToString(),
                ExceptionMessage       = ex.Message,
                Exchange               = amqpQueue.ExchangeName,
                Queue                  = amqpQueue.Queue.Name,
                QueueMessageJsonString = queueMessageJson,
                Desc                   = desc,
                ServerMachineName      = Environment.MachineName,
                ServerIP               = NetworkUtil.LocalIP
            };

            return(busEx);
        }