mirror of https://github.com/abpframework/abp.git
1 changed files with 27 additions and 3 deletions
@ -1,24 +1,48 @@ |
|||||
using System.Threading.Tasks; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
using Volo.Abp.Auditing; |
using Volo.Abp.Auditing; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.Guids; |
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
namespace Volo.Abp.AuditLogging |
namespace Volo.Abp.AuditLogging |
||||
{ |
{ |
||||
public class AuditingStore : IAuditingStore, ITransientDependency |
public class AuditingStore : IAuditingStore, ITransientDependency |
||||
{ |
{ |
||||
|
public ILogger<AuditingStore> Logger { get; set; } |
||||
|
|
||||
private readonly IAuditLogRepository _auditLogRepository; |
private readonly IAuditLogRepository _auditLogRepository; |
||||
private readonly IGuidGenerator _guidGenerator; |
private readonly IGuidGenerator _guidGenerator; |
||||
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
||||
|
|
||||
public AuditingStore(IAuditLogRepository auditLogRepository, IGuidGenerator guidGenerator) |
public AuditingStore( |
||||
|
IAuditLogRepository auditLogRepository, |
||||
|
IGuidGenerator guidGenerator, |
||||
|
IUnitOfWorkManager unitOfWorkManager) |
||||
{ |
{ |
||||
_auditLogRepository = auditLogRepository; |
_auditLogRepository = auditLogRepository; |
||||
_guidGenerator = guidGenerator; |
_guidGenerator = guidGenerator; |
||||
|
_unitOfWorkManager = unitOfWorkManager; |
||||
|
|
||||
|
Logger = NullLogger<AuditingStore>.Instance; |
||||
} |
} |
||||
|
|
||||
public async Task SaveAsync(AuditLogInfo auditInfo) |
public async Task SaveAsync(AuditLogInfo auditInfo) |
||||
{ |
{ |
||||
await _auditLogRepository.InsertAsync(new AuditLog(_guidGenerator, auditInfo)); |
try |
||||
|
{ |
||||
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true)) |
||||
|
{ |
||||
|
await _auditLogRepository.InsertAsync(new AuditLog(_guidGenerator, auditInfo)); |
||||
|
await uow.SaveChangesAsync(); |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Logger.LogException(ex, LogLevel.Error); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue