Audit.net with DynamoDB Saving old and new Target as same.
See original GitHub issueDescribe the bug Unable to track old and new target object .Currently I have created a separate class library where the code for audit log is written which saves to dynamo DB and I call that through my service class as shown in code snippets below .
To Reproduce Steps or code to reproduce the behavior. ClassLibrary Code:
public class DisAuditLog:IDISAuditLog
{
private readonly ILogger<DisAuditLog> _logger;
public DisAuditLog(ILogger<DisAuditLog> logger)
{
_logger = logger;
}
public void Log(Guid auditKey,string eventType, object targetObject, string Identifier ,string userName,string centerNumber,string comments,DateTime CreationDate)
{
try
{
using var audit = AuditScope.Create(eventType, () => targetObject);
audit.SetCustomField("EventId", auditKey);
audit.SetCustomField("UserID", userName);
audit.SetCustomField("EntityName", "Donor_tblDonors");
audit.SetCustomField("CenterNumber", centerNumber);
audit.SetCustomField("PDN", PDN);
audit.SetCustomField("CreationDate", CreationDate);
audit.Comment(comments);
}
catch(Exception ex)
{
_logger.LogError(ex, "Error occured while creating audit logs");
}
}
}
Service class code for calling the log. here donor input object is passed first:
var auditkey = Guid.NewGuid();
donor.FirstName = "TestAuditBefore";
_auditLog.Log(auditkey, "Donor:Create", donor, test, "test", "test", "test", DateTime.Now);
var addedDonor = await _donorRepository.AddOrGetDonorAsync(donor);
_addedDonor.FirstName = "TestAuditAfter" + DateTime.Now; // This code is just to test if by modifying i get old and new objects.
_auditLog.Log(auditkey,"Donor:Create", addedDonor,test, "test", "test", "test", DateTime.Now);
Expected behavior Should log both old and new object under same EventId Key.
Libraries (specify the Audit.NET extensions being used including version): For example: Target .NET framework: For example:
- .NET Core 5
Additional context Add any other context about the problem here. Reading Credential is done at Startup.cs. Please let me know what additionally is required to track old and new objects
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Actually I forgot to put the update code of log method. I have Update it now above. And yes I am passing audit scope from main method and not creating a new one in my updated code. @thepirat000
Thanks for the support. Closing the issue @thepirat000