diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs index e746063b49..513861bf11 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -15,14 +16,23 @@ namespace Volo.Abp.AuditLogging string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true); + bool includeDetails = false, + CancellationToken cancellationToken = default); Task GetCountAsync( string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true); + CancellationToken cancellationToken = default); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index 1fb7fcad7f..b73fda62e7 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Net; +using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -25,10 +26,15 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true) + bool includeDetails = false, + CancellationToken cancellationToken = default) { - var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); + var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, httpStatusCode, includeDetails); var auditLogs = await query.OrderBy(sorting ?? "executionTime desc") .PageBy(skipCount, maxResultCount) @@ -41,10 +47,14 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true) + CancellationToken cancellationToken = default) { - var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); + var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, httpStatusCode); var totalCount = await query.LongCountAsync(); @@ -55,15 +65,23 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true) + bool includeDetails = false) { return DbSet.AsNoTracking() .IncludeDetails(includeDetails) .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) - .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); + .WhereIf(string.IsNullOrWhiteSpace(url), auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) + .WhereIf(string.IsNullOrWhiteSpace(userName), auditLog => auditLog.UserName != null && auditLog.UserName.ToLowerInvariant() == userName.ToLowerInvariant()) + .WhereIf(string.IsNullOrWhiteSpace(applicationName), auditLog => auditLog.ApplicationName != null && auditLog.ApplicationName.ToLowerInvariant() == applicationName.ToLowerInvariant()) + .WhereIf(string.IsNullOrWhiteSpace(correlationId), auditLog => auditLog.CorrelationId != null && auditLog.CorrelationId.ToLowerInvariant() == correlationId.ToLowerInvariant()) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) + .WhereIf(maxExecutionDuration != null && maxExecutionDuration > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration) + .WhereIf(minExecutionDuration != null && minExecutionDuration > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); } public override IQueryable WithDetails() diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index 662cfdbc2e..c47965fdb7 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Net; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -19,19 +20,40 @@ namespace Volo.Abp.AuditLogging.MongoDB } - public async Task> GetListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0, - string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = true) + public async Task> GetListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + string httpMethod = null, + string url = null, + string userName = null, + string applicationName = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) { - var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); + var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, httpStatusCode, includeDetails); return await query.OrderBy(sorting ?? "executionTime desc").As>() .PageBy>(skipCount, maxResultCount) .ToListAsync(); } - public async Task GetCountAsync(string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = true) + public async Task GetCountAsync( + string httpMethod = null, + string url = null, + string userName = null, + string applicationName = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, + HttpStatusCode? httpStatusCode = null, + CancellationToken cancellationToken = default) { - var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); + var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, httpStatusCode); var count = await query.As>().LongCountAsync(); @@ -42,14 +64,22 @@ namespace Volo.Abp.AuditLogging.MongoDB string httpMethod = null, string url = null, string userName = null, + string applicationName = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = true) + bool includeDetails = false) { return GetMongoQueryable() .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) - .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); + .WhereIf(string.IsNullOrWhiteSpace(url), auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) + .WhereIf(string.IsNullOrWhiteSpace(userName), auditLog => auditLog.UserName != null && auditLog.UserName == userName) + .WhereIf(string.IsNullOrWhiteSpace(applicationName), auditLog => auditLog.ApplicationName == applicationName) + .WhereIf(string.IsNullOrWhiteSpace(correlationId), auditLog => auditLog.CorrelationId == correlationId) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) + .WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration) + .WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration); ; } } }