Beispiel #1
0
        public void Intercept(IInvocation invocation)
        {
            if (!AuditingHelper.ShouldSaveAudit(invocation.MethodInvocationTarget, _configuration, ZbpSession))
            {
                invocation.Proceed();
                return;
            }

            var auditInfo = new AuditInfo
            {
                TenantId = ZbpSession.TenantId,
                UserId = ZbpSession.UserId,
                ServiceName = invocation.MethodInvocationTarget.DeclaringType != null
                              ? invocation.MethodInvocationTarget.DeclaringType.FullName
                              : "",
                MethodName = invocation.MethodInvocationTarget.Name,
                Parameters = ConvertArgumentsToJson(invocation),
                ExecutionTime = Clock.Now
            };

            _auditInfoProvider.Fill(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); //TODO: Call async when target method is async.
            }
        }
Beispiel #2
0
 public Task SaveAsync(AuditInfo auditInfo)
 {
     Logger.Info(auditInfo.ToString());
     return Task.FromResult(0);
 }
Beispiel #3
0
        private void HandleAuditingBeforeAction(ActionExecutingContext filterContext)
        {
            if (!ShouldSaveAudit(filterContext))
            {
                _auditInfo = null;
                return;
            }

            var methodInfo = GetMethodInfo(filterContext.ActionDescriptor);

            _actionStopwatch = Stopwatch.StartNew();
            _auditInfo = new AuditInfo
            {
                TenantId = ZbpSession.TenantId,
                UserId = ZbpSession.UserId,
                ServiceName = methodInfo.DeclaringType != null
                                ? methodInfo.DeclaringType.FullName
                                : filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                MethodName = methodInfo.Name,
                Parameters = ConvertArgumentsToJson(filterContext.ActionParameters),
                ExecutionTime = Clock.Now
            };
        }
Beispiel #4
0
 public void Fill(AuditInfo auditInfo)
 {
 }
Beispiel #5
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));
 }