Skip to content

7uan7D/AuditLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AuditLogger

AuditLogger is a lightweight .NET Framework class library for recording application activity to SQL Server. It is designed for CRUD auditing scenarios where you need a simple way to store who changed what, when, and from where.

Highlights

  • Logs create, update, and delete actions
  • Captures changed fields as JSON
  • Stores user, entity, item ID, origin, and optional metadata
  • Includes helper methods for action detection and object comparison

Tech Stack

  • C#
  • .NET Framework 4.5
  • SQL Server
  • Newtonsoft.Json

Database Setup

Run AuditLogger/create_auditlog_table.sql to create the AuditLogs table before using the library.

Example

var logger = new SqlAuditLogger(connectionString);

var context = AuditHelper.BuildContext(entity, userId, originIp);
var action = AuditHelper.DetectAction(oldEntity, entity);
var changes = AuditHelper.DiffObjects(oldEntity, entity);

var entry = new AuditLogEntry
{
    UserId = context.UserId,
    Action = action,
    TableName = context.TableName,
    ItemId = itemId,
    Changes = changes,
    Origin = context.OriginIp
};

await logger.LogAsync(entry);

Repository Structure

  • AuditLogger/: class library source code
  • AuditLogger/create_auditlog_table.sql: SQL script for audit table creation
  • AuditLogger.sln: Visual Studio solution

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages