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…
- Create a new console application project named
AuditEventListener
. - Add a reference to our
Eg.Core
model from Chapter 2, Models and Mappings. - Install the
NHibernate
andlog4net
packages using the NuGet Package Manager Console by executing the following commands:Install-Package NHibernate Install-Package log4net
- Add an
App.config
with a standard NHibernate and log4net configuration. - 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.