O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, I'll show you how we can easily create an audit log to track changes to our 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 1, along with NHibernate.dll and log4net.dll.
  3. Add an App.config with a standard NHibernate and log4net configuration.
  4. Just before the end of the sessionfactory element, add the following three event elements:
    <event type="pre-insert"> <listener class="AuditEventListener.EventListener, AuditEventListener" /> </event> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required