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. } }
public Task SaveAsync(AuditInfo auditInfo) { Logger.Info(auditInfo.ToString()); return Task.FromResult(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 }; }
public void Fill(AuditInfo auditInfo) { }
/// <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)); }