Profiling NHibernate or Linq to SQL in an EPiServer CMS solution

Hibernating Rhinos has two really good products for profiling applications that are using NHibernate or Linq to SQL, NHibernate Profiler and Linq to Sql Profiler. To profile your application you need to reference an appender and initialize it upon startup. This can easily be done in several ways in EPiServer CMS, using HTTP modules, the application start event on HttpApplication or with PlugInAttributes to mention a few. I prefer to create an InitializationModule in a separate assembly, which gives you the ability to add and remove profiling by adding/removing the assembly to/form the Bin folder. This way, you don’t have to release a new version of your code to enable profiling and it’s easy to reuse in all your solutions.

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class NHibernateProfilerInitializationModule : IInitializableModule
{
	#region IInitializableModule Members

	public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
	{
		NHibernateProfiler.Initialize();
	}

	public void Preload(string[] parameters)
	{
	}

	public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
	{
	}

	#endregion
}
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class LinqToSqlProfilerInitializationModule : IInitializableModule
{
	#region IInitializableModule Members

	public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
	{
		LinqToSqlProfiler.Initialize();
	}

	public void Preload(string[] parameters)
	{
	}

	public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
	{
	}

	#endregion
}
blog comments powered by Disqus