Other

Designing an audit trail: storing before and after values of a change

DEV Community: #dotnet Jeff Tsai
Other

An experience report on building an audit layer for an ERP: storing identity without joins, writing a save's whole before/after diff as a single DiffGram row, and keeping the audit write outside the business transaction.

Key points

  • Identity is stored as id plus display name because the log database is separate and cross-database joins do not exist.
  • The login record encodes the outcome in one event value and keeps the failure reason apart from the terse UI message.
  • Access logging is off by default, covers single-record reads only, and can be enabled per form.
  • The change row is written outside the transaction; failures are queued, fall back to a synchronous write, or go to a file.
  • One save produces one row holding the whole before/after set via GetChanges() and a DiffGram XML column.
  • Because the DiffGram carries its own schema, old rows stay readable years later without any migration.

Real-world use

  • ERP applications where someone asks months later who changed a record and from what value to what value
  • Compliance scenarios where you must prove who opened a specific customer record
  • Multi-database setups where the log database is moved to another machine or split by year
  • High-volume order saving where the audit write must not slow down or break the business operation

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message