Browse Source

AuditingStore optional HideErrors added

pull/1111/head
musademir 8 years ago
parent
commit
ef758b5443
  1. 9
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs
  2. 28
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs

9
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs

@ -9,6 +9,12 @@ namespace Volo.Abp.Auditing
{ {
//TODO: Consider to add an option to disable auditing for application service methods? //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> /// <summary>
/// Default: true. /// Default: true.
/// </summary> /// </summary>
@ -36,11 +42,12 @@ namespace Volo.Abp.Auditing
/// Default: false. /// Default: false.
/// </summary> /// </summary>
public bool IsEnabledForGetRequests { get; set; } public bool IsEnabledForGetRequests { get; set; }
public AbpAuditingOptions() public AbpAuditingOptions()
{ {
IsEnabled = true; IsEnabled = true;
IsEnabledForAnonymousUsers = true; IsEnabledForAnonymousUsers = true;
HideErrors = true;
Contributors = new List<AuditLogContributor>(); Contributors = new List<AuditLogContributor>();

28
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs

@ -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)
{ {

Loading…
Cancel
Save