views:

40

answers:

2

I'm building a web application and using lazy-loading as default. I would like the application to keep going even if I "forgot" (or did it by purpose) to load some sub-entities. This will make the application robust enough to avoid NullReferenceException.

BUT - I do want to count, somehow, the number of times lazy loading happened and log it if some threshold reached (for example, if single page rendering used more than 10 lazy loading, I would like to write a WARN message to my log and monitor it, to understand bottlenecks and naive implementation).

Is there a way to easily pull it off somehow?

A: 

I'd recommend you implement the monitoring of nhibernate requests per page as presented by Ayende Rahien on his blog. It allows you to get an idea of where your pages are lazy loading the most. You can usually pinpoint the pages where the objects are lazy loaded by sorting the hits to the database for each page.

It requires log4net in your project but i'd consider this a good thing :)

samy
thanks! pretty close to what I've been looking for, I can make it from there :)
Oren Ellenbogen
+1  A: 

NHProf monitors that, among other things.

It's commercial, but it's a great tool for working with NH.

Diego Mijelshon
I'll have a look as well, thanks!
Oren Ellenbogen