pull/1120/head
Yunus Emre Kalkan 7 years ago
commit 416c15c52a

@ -9,6 +9,12 @@ namespace Volo.Abp.Auditing
{
//TODO: Consider to add an option to disable auditing for application service methods?
/// <summary>
/// If this value is true, auditing will not throw an exceptions and it will log it when an error occurred while saving AuditLog.
/// Default: true.
/// </summary>
public bool HideErrors { get; set; }
/// <summary>
/// Default: true.
/// </summary>
@ -41,6 +47,7 @@ namespace Volo.Abp.Auditing
{
IsEnabled = true;
IsEnabledForAnonymousUsers = true;
HideErrors = true;
Contributors = new List<AuditLogContributor>();

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

Loading…
Cancel
Save