|
|
@ -2,6 +2,7 @@ |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
|
|
using Microsoft.Extensions.Options; |
|
|
using Volo.Abp.Auditing; |
|
|
using Volo.Abp.Auditing; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.Guids; |
|
|
using Volo.Abp.Guids; |
|
|
@ -16,29 +17,42 @@ namespace Volo.Abp.AuditLogging |
|
|
private readonly IAuditLogRepository _auditLogRepository; |
|
|
private readonly IAuditLogRepository _auditLogRepository; |
|
|
private readonly IGuidGenerator _guidGenerator; |
|
|
private readonly IGuidGenerator _guidGenerator; |
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
|
|
private readonly AbpAuditingOptions Options; |
|
|
|
|
|
|
|
|
public AuditingStore( |
|
|
public AuditingStore( |
|
|
IAuditLogRepository auditLogRepository, |
|
|
IAuditLogRepository auditLogRepository, |
|
|
IGuidGenerator guidGenerator, |
|
|
IGuidGenerator guidGenerator, |
|
|
IUnitOfWorkManager unitOfWorkManager) |
|
|
IUnitOfWorkManager unitOfWorkManager, |
|
|
|
|
|
IOptions<AbpAuditingOptions> options) |
|
|
{ |
|
|
{ |
|
|
_auditLogRepository = auditLogRepository; |
|
|
_auditLogRepository = auditLogRepository; |
|
|
_guidGenerator = guidGenerator; |
|
|
_guidGenerator = guidGenerator; |
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
|
|
Options = options.Value; |
|
|
|
|
|
|
|
|
Logger = NullLogger<AuditingStore>.Instance; |
|
|
Logger = NullLogger<AuditingStore>.Instance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task SaveLogAsync(AuditLogInfo auditInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true)) |
|
|
|
|
|
{ |
|
|
|
|
|
var auditLog = new AuditLog(_guidGenerator, auditInfo); |
|
|
|
|
|
await _auditLogRepository.InsertAsync(auditLog); |
|
|
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
public async Task SaveAsync(AuditLogInfo auditInfo) |
|
|
public async Task SaveAsync(AuditLogInfo auditInfo) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!Options.HideErrors) |
|
|
|
|
|
{ |
|
|
|
|
|
await SaveLogAsync(auditInfo); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true)) |
|
|
await SaveLogAsync(auditInfo); |
|
|
{ |
|
|
|
|
|
var auditLog = new AuditLog(_guidGenerator, auditInfo); |
|
|
|
|
|
await _auditLogRepository.InsertAsync(auditLog); |
|
|
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
|