Merge pull request #8514 from abpframework/maliming/audit-patch

Add exception to audit log if it not record.
pull/8515/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit 2f669427bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -45,19 +45,26 @@ namespace Volo.Abp.AspNetCore.Auditing
var hasError = false;
using (var saveHandle = _auditingManager.BeginScope())
{
Debug.Assert(_auditingManager.Current != null);
try
{
await next(context);
Debug.Assert(_auditingManager.Current != null);
if (_auditingManager.Current.Log.Exceptions.Any())
{
hasError = true;
}
}
catch (Exception)
catch (Exception ex)
{
hasError = true;
if (!_auditingManager.Current.Log.Exceptions.Contains(ex))
{
_auditingManager.Current.Log.Exceptions.Add(ex);
}
throw;
}
finally

@ -31,10 +31,18 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
{
throw new UserFriendlyException("Exception occurred!");
}
[Route("audit-fail-object")]
public object AuditFailForGetRequestsReturningObject()
{
throw new UserFriendlyException("Exception occurred!");
}
[HttpGet]
[Route("audit-activate-failed")]
public IActionResult AuditActivateFailed([FromServices] AbpAuditingOptions options)
{
return Ok();
}
}
}

@ -74,5 +74,20 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Activate_Controller_Failed()
{
_options.IsEnabledForGetRequests = true;
_options.AlwaysLogOnException = true;
try
{
await GetResponseAsync("api/audit-test/audit-activate-failed", System.Net.HttpStatusCode.InternalServerError);
}
catch { }
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x => x.Exceptions.Any()));
}
}
}

@ -34,5 +34,10 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
{
throw new UserFriendlyException("Exception occurred!");
}
public IActionResult OnGetAuditActivateFailed([FromServices] AbpAuditingOptions options)
{
return new OkResult();
}
}
}

@ -73,5 +73,20 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Activate_Page_Failed()
{
_options.IsEnabledForGetRequests = true;
_options.AlwaysLogOnException = true;
try
{
await GetResponseAsync("/Auditing/AuditTestPage?handler=AuditActivateFailed", System.Net.HttpStatusCode.InternalServerError);
}
catch { }
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x => x.Exceptions.Any()));
}
}
}

Loading…
Cancel
Save