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.

Code sharing for audit log in single table.

See original GitHub issue

Hi

I was having a requirement to generate report for work done by user on daily basis and the details of actions (Insert/Update/Delete) by user. Initially i was using ICaptureLogRow but i have so many table and i have to create a copy of each table and a log class for each module. My table also changed frequently so maintaining log table and log class was becoming pain for me. So i created custom behaviour to log all changes in single table.

I am sharing code by thinking that it may be helpful for someone else. DBScripts for Table, Stored Procedure and Code file is attached. DB Scripts SQLServer_AuditScript.txt

Code File AuditBehavior.txt

How To Use

  1. Run the DBScript in your SQL Server Database
  2. If there is already a column named Identity then inherit your RowClass with IAuditLog Ex:
public sealed class UserRow : LoggingRow, IIdRow, INameRow, IIsActiveRow, IAuditLog
{
}
  1. If you want to save any other column value as RowId in AuditTable then use following
public sealed class UserRow : LoggingRow, IIdRow, INameRow, IIsActiveRow, IExAuditLog
{
         public Int32Field UserId
        {
            get { return Fields.IdField; }
        }
}

Here is screenshot of log table changelog

Hope this will be helpful for someone. Please let me know if you find any improvement in this or have any suggestions.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
ramveersghcommented, Jul 7, 2016

Added the Wiki Page for this. Wiki Page

0reactions
Qasem2022commented, Oct 11, 2022

great effort Thank you for posting the code

But when I apply the code, I see an error in the process of deleting and adding (Object reference not set to an instance of an object) can you help Also, the class mentioned in Namespace (http://using IBS_ACOC.Modules.Common.Enums;) I don’t know what it is / can it be published? There is an error in Namespace (//using IBS_ACOC.DAL;) / Is it related to the error?

Once again thank you

hope for help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code sharing for audit log in single table. · Issue #874
So i created custom behaviour to log all changes in single table. I am sharing code by thinking that it may be helpful...
Read more >
Use sharing auditing in the audit log
Admin can learn how to use sharing auditing in the Microsoft 365 ... Logs one of the following events, based on how the...
Read more >
Sql Server - How to convert Audit log into a table?
We use a shared folder because we have multiple servers writing audit information and we use ONE capture process that runs on a...
Read more >
Audit tables: Each field for table or one table
Each table has a copy plus the three audit fields and every time a user changes a record the audit table gets inserted...
Read more >
Various techniques to audit SQL Server databases
Organizations are now tasked with auditing access to records, ... A trigger can exist for only one table, so you will need to...
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