Creating an audit-event listener

Auditing is another common security-related task. An audit log is an append-only record of changes in a system that allows you to trace a particular action back to its source. In this recipe, we will show you how you can easily create an audit log to track changes to your entities.

How to do it…

  1. Create a new console application project named AuditEventListener.
  2. Add a reference to our Eg.Core model from Chapter 2, Models and Mappings.
  3. Install the NHibernate and log4net packages using the NuGet Package Manager Console by executing the following commands:
    Install-Package NHibernate
    Install-Package log4net
    
  4. Add an App.config with a standard NHibernate and log4net configuration.
  5. Just before the end of the sessionfactory

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.