Skip to content

Commit

Permalink
Merge pull request #3174 from abpframework/Cotur-Virtualization-Audit…
Browse files Browse the repository at this point in the history
…Logging

Make AuditLogging module services easily overridable by inheritance
  • Loading branch information
hikalkan authored Mar 18, 2020
2 parents 6302511 + 8567def commit a11914c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ public class AuditingStore : IAuditingStore, ITransientDependency
{
public ILogger<AuditingStore> Logger { get; set; }

private readonly IAuditLogRepository _auditLogRepository;
private readonly IGuidGenerator _guidGenerator;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly AbpAuditingOptions Options;
protected IAuditLogRepository AuditLogRepository { get; }
protected IGuidGenerator GuidGenerator { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected AbpAuditingOptions Options { get; }

public AuditingStore(
IAuditLogRepository auditLogRepository,
IGuidGenerator guidGenerator,
IUnitOfWorkManager unitOfWorkManager,
IOptions<AbpAuditingOptions> options)
{
_auditLogRepository = auditLogRepository;
_guidGenerator = guidGenerator;
_unitOfWorkManager = unitOfWorkManager;
AuditLogRepository = auditLogRepository;
GuidGenerator = guidGenerator;
UnitOfWorkManager = unitOfWorkManager;
Options = options.Value;

Logger = NullLogger<AuditingStore>.Instance;
}

public async Task SaveAsync(AuditLogInfo auditInfo)
public virtual async Task SaveAsync(AuditLogInfo auditInfo)
{
if (!Options.HideErrors)
{
Expand All @@ -54,9 +54,9 @@ public async Task SaveAsync(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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public EfCoreAuditLogRepository(IDbContextProvider<IAuditLoggingDbContext> dbCon

}

public async Task<List<AuditLog>> GetListAsync(
public virtual async Task<List<AuditLog>> GetListAsync(
string sorting = null,
int maxResultCount = 50,
int skipCount = 0,
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task<List<AuditLog>> GetListAsync(
return auditLogs;
}

public async Task<long> GetCountAsync(
public virtual async Task<long> GetCountAsync(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null,
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task<long> GetCountAsync(
return totalCount;
}

private IQueryable<AuditLog> GetListQuery(
protected virtual IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null,
Expand Down Expand Up @@ -123,7 +123,7 @@ private IQueryable<AuditLog> GetListQuery(
.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()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MongoAuditLogRepository(IMongoDbContextProvider<IAuditLoggingMongoDbConte

}

public async Task<List<AuditLog>> GetListAsync(
public virtual async Task<List<AuditLog>> GetListAsync(
string sorting = null,
int maxResultCount = 50,
int skipCount = 0,
Expand Down Expand Up @@ -58,7 +58,7 @@ public async Task<List<AuditLog>> GetListAsync(
.ToListAsync(GetCancellationToken(cancellationToken));
}

public async Task<long> GetCountAsync(
public virtual async Task<long> GetCountAsync(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null,
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task<long> GetCountAsync(
return count;
}

private IQueryable<AuditLog> GetListQuery(
protected virtual IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null,
Expand Down Expand Up @@ -122,7 +122,7 @@ private IQueryable<AuditLog> GetListQuery(
}


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()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
Expand Down

0 comments on commit a11914c

Please sign in to comment.