public bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false) { if (!_configuration.IsEnabled) { return(false); } if (!_configuration.IsEnabledForAnonymousUsers && (BysSession?.GetUserId() == null)) { return(false); } if (methodInfo == null) { return(false); } if (!methodInfo.IsPublic) { return(false); } if (methodInfo.IsDefined(typeof(AuditedAttribute), true)) { return(true); } if (methodInfo.IsDefined(typeof(DisableAuditingAttribute), true)) { return(false); } if (methodInfo.IsDefined(typeof(HttpPostAttribute), true)) { return(true); } var classType = methodInfo.DeclaringType; if (classType != null) { if (classType.GetTypeInfo().IsDefined(typeof(AuditedAttribute), true)) { return(true); } if (classType.GetTypeInfo().IsDefined(typeof(DisableAuditingAttribute), true)) { return(false); } if (_configuration.Selectors.Any(selector => selector.Predicate(classType))) { return(true); } } return(defaultValue); }
public AuditInfo CreateAuditInfo(Type type, MethodInfo method, IDictionary <string, object> arguments) { var auditInfo = new AuditInfo { UserId = BysSession.GetUserId(), ServiceName = type != null ? type.FullName : "", MethodName = method.Name, Parameters = ConvertArgumentsToJson(arguments), ExecutionTime = Clock.Now }; try { _auditInfoProvider.Fill(auditInfo); } catch (Exception ex) { Logger.LogWarning(ex.ToString(), ex); } return(auditInfo); }