1. To get started with this powerful profiler, simply install the NuGet package (look for nHibernate Profiler).

 

nHibernate_profiler_nuget 

 

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.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.