From 7f84239fdacf202de3edbfe65157d5ad3143bd51 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 16 Jul 2018 09:47:12 +0300 Subject: [PATCH] Handle exceptions and use new transaction inside AuditingStore --- .../Volo/Abp/AuditLogging/AuditingStore.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs index 84e65e832b..9df4620137 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs @@ -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.DependencyInjection; using Volo.Abp.Guids; +using Volo.Abp.Uow; namespace Volo.Abp.AuditLogging { public class AuditingStore : IAuditingStore, ITransientDependency { + public ILogger Logger { get; set; } + private readonly IAuditLogRepository _auditLogRepository; private readonly IGuidGenerator _guidGenerator; + private readonly IUnitOfWorkManager _unitOfWorkManager; - public AuditingStore(IAuditLogRepository auditLogRepository, IGuidGenerator guidGenerator) + public AuditingStore( + IAuditLogRepository auditLogRepository, + IGuidGenerator guidGenerator, + IUnitOfWorkManager unitOfWorkManager) { _auditLogRepository = auditLogRepository; _guidGenerator = guidGenerator; + _unitOfWorkManager = unitOfWorkManager; + + Logger = NullLogger.Instance; } 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); + } } } }