Search code examples
nhibernateloggingaudit

Audit Logging Strategies


I am trying to decide on the best method for audit logging within my application. The main reason for the log is reporting the sequence of events (changes).

I have a hierarchy of Objects, I need to create reports when something changes on any part of that hierarchy, at a latter date.

I think that I have three options:

  1. Have a log for each table and therefore matching the hierarchy of objects then creating a view for the report.
  2. Flatten the hierarchy and de-normalise the table, making reporting easier - simple select statement.
  3. Have one log table and have a record for each change making reporting harder but more flexible to changes.

I am currently leaning towards option 1.


Solution

  • An audit log is basically a chronological list of events that occurred, who performed these events, and what the events were.

    I think a flat view would be better as it can be easily ordered and queried. So I'm leaning more towards your option #2/#3.

    Include things like the transaction type, the time, the user id, a description of what's changed, and other pertinent information related to your product.

    You can also add things to your product over time and you won't need to continually modify your audit log module.