public void Fill(AuditInfo auditInfo)
        {
            var httpContext = HttpContext.Current ?? _httpContext;
            if (httpContext == null)
            {
                return;
            }

            try
            {
                auditInfo.BrowserInfo = GetBrowserInfo(httpContext);
                auditInfo.ClientIpAddress = GetClientIpAddress(httpContext);
                auditInfo.ClientName = GetComputerName(httpContext);
            }
            catch (Exception ex)
            {
                Logger.Warn("Could not obtain web parameters for audit info.");
                Logger.Warn(ex.ToString(), ex);
            }
        }
        private void PerformSyncAuditing(IInvocation invocation, AuditInfo auditInfo)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                auditInfo.Exception = ex;
                throw;
            }
            finally
            {
                stopwatch.Stop();
                auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                AuditingStore.Save(auditInfo);
            }
        }
        private AuditInfo CreateAuditInfo(IInvocation invocation)
        {
            var auditInfo = new AuditInfo
            {
                TenantId = OwSession.TenantId,
                UserId = OwSession.UserId,
                ImpersonatorUserId = OwSession.ImpersonatorUserId,
                ImpersonatorTenantId = OwSession.ImpersonatorTenantId,
                ServiceName = invocation.MethodInvocationTarget.DeclaringType != null
                    ? invocation.MethodInvocationTarget.DeclaringType.FullName
                    : "",
                MethodName = invocation.MethodInvocationTarget.Name,
                Parameters = ConvertArgumentsToJson(invocation),
                ExecutionTime = Clock.Now
            };

            _auditInfoProvider.Fill(auditInfo);

            return auditInfo;
        }
 public Task SaveAsync(AuditInfo auditInfo)
 {
     Logger.Info(auditInfo.ToString());
     return Task.FromResult(0);
 }
 /// <summary>
 /// Should save audits to a persistent store.
 /// 应将审计保存到持久存储区。
 /// </summary>
 /// <param name="auditingStore">Auditing store (审计存储)</param>
 /// <param name="auditInfo">Audit informations (审计信息)</param>
 public static void Save(this IAuditingStore auditingStore, AuditInfo auditInfo)
 {
     AsyncHelper.RunSync(() => auditingStore.SaveAsync(auditInfo));
 }
Beispiel #6
0
        private void HandleAuditingBeforeAction(ActionExecutingContext filterContext)
        {
            if (!ShouldSaveAudit(filterContext))
            {
                _auditInfo = null;
                return;
            }

            _actionStopwatch = Stopwatch.StartNew();
            _auditInfo = new AuditInfo
            {
                TenantId = OwSession.TenantId,
                UserId = OwSession.UserId,
                ImpersonatorUserId = OwSession.ImpersonatorUserId,
                ImpersonatorTenantId = OwSession.ImpersonatorTenantId,
                ServiceName = _currentMethodInfo.DeclaringType != null
                                ? _currentMethodInfo.DeclaringType.FullName
                                : filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                MethodName = _currentMethodInfo.Name,
                Parameters = ConvertArgumentsToJson(filterContext.ActionParameters),
                ExecutionTime = Clock.Now
            };
        }
        private void SaveAuditInfo(AuditInfo auditInfo, Stopwatch stopwatch, Exception exception)
        {
            stopwatch.Stop();
            auditInfo.Exception = exception;
            auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);

            using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress))
            {
                AuditingStore.Save(auditInfo);
                uow.Complete();
            }
        }
        private void PerformAsyncAuditing(IInvocation invocation, AuditInfo auditInfo)
        {
            var stopwatch = Stopwatch.StartNew();

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithFinally(
                    (Task) invocation.ReturnValue,
                    exception => SaveAuditInfo(auditInfo, stopwatch, exception)
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithFinallyAndGetResult(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    exception => SaveAuditInfo(auditInfo, stopwatch, exception)
                    );
            }
        }