question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Audit.net with DynamoDB Saving old and new Target as same.

See original GitHub issue

Describe 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: image 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

@thepirat000 @bgrainger

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jainashish1711commented, May 14, 2021

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

0reactions
jainashish1711commented, May 15, 2021

Thanks for the support. Closing the issue @thepirat000

Read more comments on GitHub >

github_iconTop Results From Across the Web

Old and new values are same in audit.net · Issue #167
The target is accessed when the audit scope is created (old) and when the scope is disposed (new). Are you modifying the model...
Read more >
DynamoDB Streams Use Cases and Design Patterns
How do you audit or archive data? How do you replicate data across multiple tables (similar to that of materialized views/streams/replication in ...
Read more >
Audit.NET connected object save issue
With the latest version of Audit.EntityFramework (15.0.2), you can now ignore property matching only for certain audit types, as follows:
Read more >
Using DynamoDB to track changes to DynamoDB
We will capture the entire event, the old and new data, ... get all the records from the orders table and store them...
Read more >
Amazon DynamoDB Cheat Sheet
The table must have DynamoDB Streams enabled, with the stream containing both the new and the old images of the item. None of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found