Merge pull request #3174 from abpframework/Cotur-Virtualization-AuditLogging

Make AuditLogging module services easily overridable by inheritance
pull/3178/head
Halil İbrahim Kalkan 6 years ago committed by GitHub
commit a11914c173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,10 +14,10 @@ namespace Volo.Abp.AuditLogging
{ {
public ILogger<AuditingStore> Logger { get; set; } public ILogger<AuditingStore> Logger { get; set; }
private readonly IAuditLogRepository _auditLogRepository; protected IAuditLogRepository AuditLogRepository { get; }
private readonly IGuidGenerator _guidGenerator; protected IGuidGenerator GuidGenerator { get; }
private readonly IUnitOfWorkManager _unitOfWorkManager; protected IUnitOfWorkManager UnitOfWorkManager { get; }
private readonly AbpAuditingOptions Options; protected AbpAuditingOptions Options { get; }
public AuditingStore( public AuditingStore(
IAuditLogRepository auditLogRepository, IAuditLogRepository auditLogRepository,
@ -25,15 +25,15 @@ namespace Volo.Abp.AuditLogging
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager,
IOptions<AbpAuditingOptions> options) IOptions<AbpAuditingOptions> options)
{ {
_auditLogRepository = auditLogRepository; AuditLogRepository = auditLogRepository;
_guidGenerator = guidGenerator; GuidGenerator = guidGenerator;
_unitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
Options = options.Value; Options = options.Value;
Logger = NullLogger<AuditingStore>.Instance; Logger = NullLogger<AuditingStore>.Instance;
} }
public async Task SaveAsync(AuditLogInfo auditInfo) public virtual async Task SaveAsync(AuditLogInfo auditInfo)
{ {
if (!Options.HideErrors) if (!Options.HideErrors)
{ {
@ -54,9 +54,9 @@ namespace Volo.Abp.AuditLogging
protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo) protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo)
{ {
using (var uow = _unitOfWorkManager.Begin(true)) using (var uow = UnitOfWorkManager.Begin(true))
{ {
await _auditLogRepository.InsertAsync(new AuditLog(_guidGenerator, auditInfo)); await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, auditInfo));
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
} }

@ -19,7 +19,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
} }
public async Task<List<AuditLog>> GetListAsync( public virtual async Task<List<AuditLog>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
int skipCount = 0, int skipCount = 0,
@ -59,7 +59,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return auditLogs; return auditLogs;
} }
public async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
@ -92,7 +92,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return totalCount; return totalCount;
} }
private IQueryable<AuditLog> GetListQuery( protected virtual IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
@ -123,7 +123,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
.WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); .WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration);
} }
public async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate)
{ {
var result = await DbSet.AsNoTracking() var result = await DbSet.AsNoTracking()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)

@ -20,7 +20,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
} }
public async Task<List<AuditLog>> GetListAsync( public virtual async Task<List<AuditLog>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
int skipCount = 0, int skipCount = 0,
@ -58,7 +58,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
@ -92,7 +92,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
return count; return count;
} }
private IQueryable<AuditLog> GetListQuery( protected virtual IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
@ -122,7 +122,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
} }
public async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate)
{ {
var result = await GetMongoQueryable() var result = await GetMongoQueryable()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)

Loading…
Cancel
Save