Hibernating Rhinos – nHibernate Profiler
1. To get started with this powerful profiler, simply install the NuGet package (look for nHibernate Profiler).
2.Installing it places all the required assemblies in your project AND provides you with a Bootstrapper class to launch the profiler.
1: public static class NHibernateProfilerBootstrapper
2: {
3: public static void PreStart()
4: {
5: // Initialize the profiler
6: NHibernateProfiler.Initialize();
7:
8: // You can also use the profiler in an offline manner.
9: // This will generate a file with a snapshot of all the NHibernate activity in the application,
10: // which you can use for later analysis by loading the file into the profiler.
11: // var filename = @"c:\profiler-log";
12: // NHibernateProfiler.InitializeOfflineProfiling(filename);
13: }
14: }
3. The only caveat I ran into was that even though the Bootstrapper initialization fired correctly (and launched the UI for the profiler), it did not capture any nHibernate traffic. To work around this, one can place the initialization code in Global.asax – to ensure it gets fired.
Global.asax.cs
1: protected void Application_Start(object sender, EventArgs e)
2: {
3: HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
4: }
Once I had this code in place, the profiler launched correctly AND captured traffic the way it was intended to.
Leave a Reply