コード例 #1
0
        /// <summary>
        /// 创建操作日志对象
        /// </summary>
        /// <param name="invocation"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public Operationlog CreateOperationlog(IInvocation invocation, IDictionary <string, object> arguments)
        {
            var    opeartionlogConfig = GetOpeartionlogConfig(invocation);
            string jsonString         = ConvertArgumentsToJson(arguments);
            var    operationlog       = new Operationlog
            {
                OperationUserId = GetOperationUserId(arguments),
                Parameters      = jsonString,
                OperationType   = opeartionlogConfig.OperationType,
                Module          = opeartionlogConfig.Module,
            };

            try
            {
                operationlog.LogContext      = opeartionlogConfig.LogFormat.Subtitute(ObjectFormat.Instance, arguments).TruncateWithPostfix(200);
                operationlog.BrowserInfo     = ServiceContext.GetValue("User-Agent").TruncateWithPostfix(64);
                operationlog.ClientIpAddress = ServiceContext.ClientIP;
                operationlog.ClientName      = ServiceContext.GetValue("ClientName");
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }

            return(operationlog);
        }
コード例 #2
0
        /// <summary>
        /// 保存操作日志对象
        /// </summary>
        /// <param name="operationlog"></param>
        public async Task SaveAsync(Operationlog operationlog)
        {
            using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
            {
                await _operationlogRepository.InsertAsync(operationlog);

                await uow.CompleteAsync();
            }
        }