dinsdag 27 mei 2008

Filtering your Nhibernate SQL Log: The good way

Apparently my previous post about filtering out the unique sql statements NHibernate fires at your database is a quick and dirty hack.  Sure it works but why create a complete new appender  if all you want to do is decorate the existing ones with filtering.  If I would have read the documentation that the good people of log4net have prepared for the world, I would have noticed the concept of Filters.  These form a chain that the logging event has to pass through in order to actually get logged.

Here is the same code that should do the trick using the filters, remember to add this filter in your appender declaration in the configuration file

public class NHibernateUniqueQueryFilter : FilterSkeleton { private static readonly List<String> statements = new List<string>(); public override FilterDecision Decide(LoggingEvent loggingEvent) { var message = loggingEvent.RenderedMessage; var index = loggingEvent.RenderedMessage.IndexOf(";"); if (index != -1) { message = loggingEvent.RenderedMessage.Substring(0, index); } if (statements.Contains(message)) { return FilterDecision.Deny; } statements.Add(message); return FilterDecision.Accept; } }

1 opmerking:

Anoniem zei

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!