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.
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
element, add the following three event elements:<event type="pre-insert"> <listener class="AuditEventListener.EventListener, AuditEventListener" /> </event> <event type="pre-update"> <listener class="AuditEventListener...