This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NHibernateQueryAppender : AppenderSkeleton | |
{ | |
protected override void Append(LoggingEvent loggingEvent) | |
{ | |
SqlLogger.AddSql(loggingEvent.RenderedMessage); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<log4net> | |
<appender name="GlimpseAppender" type="Headspring.Data.NHibernateQueryAppender, Headspring" /> | |
<logger name="NHibernate.SQL"> | |
<level value="DEBUG"/> | |
<appender-ref ref="GlimpseAppender" /> | |
</logger> | |
</log4net> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |