Пример #1
0
        private async Task ProcessWithNewAuditingScopeAsync(
            IAbpMethodInvocation invocation,
            AbpAuditingOptions options,
            ICurrentUser currentUser,
            IAuditingManager auditingManager,
            IAuditingHelper auditingHelper)
        {
            var hasError = false;

            using (var saveHandle = auditingManager.BeginScope())
            {
                try
                {
                    await ProceedByLoggingAsync(invocation, auditingHelper, auditingManager.Current);

                    Debug.Assert(auditingManager.Current != null);
                    if (auditingManager.Current.Log.Exceptions.Any())
                    {
                        hasError = true;
                    }
                }
                catch (Exception)
                {
                    hasError = true;
                    throw;
                }
                finally
                {
                    if (ShouldWriteAuditLog(invocation, options, currentUser, hasError))
                    {
                        await saveHandle.SaveAsync();
                    }
                }
            }
        }
Пример #2
0
        public AuditingHelper(
            IAuditSerializer auditSerializer,
            IOptions <AbpAuditingOptions> options,
            ICurrentUser currentUser,
            ICurrentTenant currentTenant,
            IClock clock,
            IAuditingStore auditingStore,
            ILogger <AuditingHelper> logger,
            IServiceProvider serviceProvider)
        {
            Options         = options.Value;
            AuditSerializer = auditSerializer;
            CurrentUser     = currentUser;
            CurrentTenant   = currentTenant;
            Clock           = clock;
            AuditingStore   = auditingStore;

            Logger          = logger;
            ServiceProvider = serviceProvider;
        }
Пример #3
0
        protected virtual bool ShouldIntercept(IAbpMethodInvocation invocation,
                                               AbpAuditingOptions options,
                                               IAuditingHelper auditingHelper)
        {
            if (!options.IsEnabled)
            {
                return(false);
            }

            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.Auditing))
            {
                return(false);
            }

            if (!auditingHelper.ShouldSaveAudit(invocation.Method))
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        private bool ShouldWriteAuditLog(
            IAbpMethodInvocation invocation,
            AbpAuditingOptions options,
            ICurrentUser currentUser,
            bool hasError)
        {
            if (options.AlwaysLogOnException && hasError)
            {
                return(true);
            }

            if (!options.IsEnabledForAnonymousUsers && !currentUser.IsAuthenticated)
            {
                return(false);
            }

            if (!options.IsEnabledForGetRequests &&
                invocation.Method.Name.StartsWith("Get", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Пример #5
0
 public JsonNetAuditSerializer(IOptions <AbpAuditingOptions> options)
 {
     Options = options.Value;
 }