Live logging with log4net and WCF part 2

In previous post I showed how to create a publish/subscribe logger with WCF and log4net, now I show you my first use of this particular appender.

When you work with nhibernate you can use show-sql configuration parameter to instruct nhibernate to show generated sql, but how can you see this output in a running windows application? You should know that NHibernate has various log4Net logger, and you can instruct the session to dump all sql code to a logger, here it is a possible configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<appender name="WCFAppender" type="LiveLogger4Log4Net.WCFAppender, LiveLogger4Log4Net">
    <layout type="log4net.Layout.PatternLayout" >
        <conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" />
    </layout>
</appender>

<logger name="NHibernate.SQL" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="WCFAppender" />
</logger>

With this configuration I instruct NHibernate to log to WCFAppender all generated SQL. Now I can attach a log viewer to a running application and look in real time to the sql instruction that nhibernate generates. You can attach more than one application, whenever you want.

image

Welcome to log4net live logging monitor :D

alk.

Tags: log4Net NHibernate

DotNetKicks Image