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.
- 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
- C#
- .NET Framework 4.5
- SQL Server
- Newtonsoft.Json
Run AuditLogger/create_auditlog_table.sql to create the AuditLogs table before using the library.
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);AuditLogger/: class library source codeAuditLogger/create_auditlog_table.sql: SQL script for audit table creationAuditLogger.sln: Visual Studio solution