public AbpAuditFilterData( Stopwatch stopwatch, AuditInfo auditInfo) { Stopwatch = stopwatch; AuditInfo = auditInfo; }
public Task SaveAsync(AuditInfo auditInfo) { if (auditInfo.Exception == null) { Logger.Info(auditInfo.ToString()); } else { Logger.Warn(auditInfo.ToString()); } return Task.FromResult(0); }
public void Fill(AuditInfo auditInfo) { if (auditInfo.ClientIpAddress.IsNullOrEmpty()) { auditInfo.ClientIpAddress = ClientInfoProvider.ClientIpAddress; } if (auditInfo.BrowserInfo.IsNullOrEmpty()) { auditInfo.BrowserInfo = ClientInfoProvider.BrowserInfo; } if (auditInfo.ClientName.IsNullOrEmpty()) { auditInfo.ClientName = ClientInfoProvider.ComputerName; } }
private AuditInfo CreateAuditInfo(IInvocation invocation) { var auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.UserId, 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 virtual void Fill(AuditInfo auditInfo) { var httpContext = _httpContextAccessor.HttpContext ?? _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); _auditingHelper.Save(auditInfo); } }
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) ); } }
public void Intercept(IInvocation invocation) { if (!AuditingHelper.ShouldSaveAudit(invocation.MethodInvocationTarget, _configuration, AbpSession)) { invocation.Proceed(); return; } var auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.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. } }
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(); } }
public void OnActionExecuting(ActionExecutingContext filterContext) { if (!ShouldSaveAudit(filterContext)) { AbpAuditFilterData.Set(filterContext.HttpContext, null); return; } var currentMethodInfo = filterContext.ActionDescriptor.GetMethodInfoOrNull(); var actionStopwatch = Stopwatch.StartNew(); var auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.UserId, ImpersonatorUserId = AbpSession.ImpersonatorUserId, ImpersonatorTenantId = AbpSession.ImpersonatorTenantId, ServiceName = currentMethodInfo.DeclaringType != null ? currentMethodInfo.DeclaringType.FullName : filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, MethodName = currentMethodInfo.Name, Parameters = ConvertArgumentsToJson(filterContext), ExecutionTime = Clock.Now }; AbpAuditFilterData.Set( filterContext.HttpContext, new AbpAuditFilterData( actionStopwatch, auditInfo ) ); }
public Task SaveAsync(AuditInfo auditInfo) { Logs.Add(auditInfo); return Task.FromResult(0); }
public virtual Task SaveAsync(AuditInfo auditInfo) { return(_auditLogRepository.InsertAsync(AuditLog.CreateFromAuditInfo(auditInfo))); }
private void SaveAuditInfo(AuditInfo auditInfo, Stopwatch stopwatch, Exception exception) { stopwatch.Stop(); auditInfo.Exception = exception; auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); _auditingHelper.Save(auditInfo); }
private AuditInfo CreateAuditInfo(ActionExecutingContext context) { var auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.UserId, ImpersonatorUserId = AbpSession.ImpersonatorUserId, ImpersonatorTenantId = AbpSession.ImpersonatorTenantId, ServiceName = context.Controller?.GetType().ToString() ?? "", MethodName = context.ActionDescriptor.DisplayName, Parameters = ConvertArgumentsToJson(context.ActionArguments), ExecutionTime = Clock.Now }; AuditInfoProvider.Fill(auditInfo); return auditInfo; }
/// <summary> /// 保存-异步 /// </summary> /// <param name="auditInfo">审计信息</param> /// <returns></returns> public Task SaveAsync(AuditInfo auditInfo) { Logger.Info(auditInfo.ToString()); return Task.FromResult(0); }
public Task SaveAsync(AuditInfo auditInfo) { return _auditLogRepository.InsertAsync(AuditLog.CreateFromAuditInfo(auditInfo)); }
private void PerformAsyncAuditing(IInvocation invocation, AuditInfo auditInfo) { var stopwatch = Stopwatch.StartNew(); invocation.Proceed(); if (invocation.Method.ReturnType == typeof(Task)) { invocation.ReturnValue = InternalAsyncHelper.WaitTaskAndAction( (Task) invocation.ReturnValue, async () => { stopwatch.Stop(); auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); await AuditingStore.SaveAsync(auditInfo); }); } else //Task<TResult> { invocation.ReturnValue = InternalAsyncHelper.CallReturnGenericTaskAfterAction( invocation.Method.ReturnType.GenericTypeArguments[0], invocation.ReturnValue, async () => { stopwatch.Stop(); auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); await AuditingStore.SaveAsync(auditInfo); }, () => { }); //TODO: Make an overload that not receives finally action! } //TODO: Handle exceptions! //try //{ //} //catch (Exception ex) //{ // auditInfo.Exception = ex; // throw; //} //finally //{ // stopwatch.Stop(); // auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); // AuditingStore.Save(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)); }
public void Save(AuditInfo auditInfo) { using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) { AuditingStore.Save(auditInfo); uow.Complete(); } }
public async Task SaveAsync(AuditInfo auditInfo) { using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) { await AuditingStore.SaveAsync(auditInfo); await uow.CompleteAsync(); } }
public AuditInfo CreateAuditInfo(MethodInfo method, IDictionary<string, object> arguments) { var auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.UserId, ImpersonatorUserId = AbpSession.ImpersonatorUserId, ImpersonatorTenantId = AbpSession.ImpersonatorTenantId, ServiceName = method.DeclaringType != null ? method.DeclaringType.FullName : "", MethodName = method.Name, Parameters = ConvertArgumentsToJson(arguments), ExecutionTime = Clock.Now }; _auditInfoProvider.Fill(auditInfo); return auditInfo; }
private void HandleAuditingBeforeAction(ActionExecutingContext filterContext) { if (!ShouldSaveAudit(filterContext)) { _auditInfo = null; return; } _actionStopwatch = Stopwatch.StartNew(); _auditInfo = new AuditInfo { TenantId = AbpSession.TenantId, UserId = AbpSession.UserId, ImpersonatorUserId = AbpSession.ImpersonatorUserId, ImpersonatorTenantId = AbpSession.ImpersonatorTenantId, ServiceName = _currentMethodInfo.DeclaringType != null ? _currentMethodInfo.DeclaringType.FullName : filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, MethodName = _currentMethodInfo.Name, Parameters = ConvertArgumentsToJson(filterContext.ActionParameters), ExecutionTime = Clock.Now }; }
public async Task SaveAsync(AuditInfo auditInfo) { await _elasticSeachClientProvider.ElasticClient.IndexAsync(auditInfo, x => x.Index(_elasticSearchConfiguration.AuditingLogIndexName)); }