Skip to content

Instantly share code, notes, and snippets.

View kurtschindler's full-sized avatar

Kurt Schindler kurtschindler

View GitHub Profile
@kurtschindler
kurtschindler / hs-blog-NHibernateGlimpsePlugin.txt
Created July 29, 2011 19:07
NHibernate Glimpse Plugin - full source
http://www.headspring.com/2011/07/creating-a-glimpse-plugin-to-log-sql-generated-by-nhibernate
The following code is all that's required to implement a Glimpse plugin that renders the SQL generated by NHibernate. A full blog post describing this is at the link above.
1. Create a custom Log4Net appender:
-----------------------------------
public class NHibernateQueryAppender : AppenderSkeleton
{
protected override void Append(LoggingEvent loggingEvent)
@kurtschindler
kurtschindler / hs-blog-log4netGlimpseAppenderConfig.xml
Created July 29, 2011 18:40
log4net config for GlimpseAppender
<log4net>
<appender name="GlimpseAppender" type="Headspring.Data.NHibernateQueryAppender, Headspring" />
<logger name="NHibernate.SQL">
<level value="DEBUG"/>
<appender-ref ref="GlimpseAppender" />
</logger>
</log4net>
@kurtschindler
kurtschindler / hs-blog-NHibernateQueryAppender.cs
Created July 29, 2011 18:38
NHibernateQueryAppender for log4net and Glimpse plugin
public class NHibernateQueryAppender : AppenderSkeleton
{
protected override void Append(LoggingEvent loggingEvent)
{
SqlLogger.AddSql(loggingEvent.RenderedMessage);
}
}
@kurtschindler
kurtschindler / hs-blog-NHGlimpsePlugin.cs
Created July 29, 2011 18:36
Glimpse Plugin for NHibernate SQL logging
[Glimpse.Core.Extensibility.GlimpsePluginAttribute()]
public class NHGlimpsePlugin : IGlimpsePlugin
{
public object GetData(HttpContextBase context)
{
var data = new List<object[]> { new[] { "Key", "Value" } };
data.Add(new object[] { "*count*", SqlLogger.Count });
foreach (var sqlString in SqlLogger.All())