NHibernate Forge
The official new home for the NHibernate for .NET community

Using NLog via Common.Logging with NHibernate

Page Details

First published by:
Matthias Gernand
on 08-16-2010
Last revision by:
Matthias Gernand
on 08-16-2010
2 people found this article useful.
Article
Comments (2)
History (9)
100% of people found this useful

Using NLog via Common.Logging with NHibernate

The NHibernate 3 Trunk-Version contains a  new Interface "ILogger" which provides
interface for custom loggers to be configured with NHibernate. NHibernate provides'
a log4net log provider for this interface out of the box. So if you are using NHibernate
with log4net just deliver the log4net Assembly as you would with NHibernate 2.x and
you are done. [:)]

But if you need or want to use an other logging framework, like NLog, you can provide
an ILogger implementation for your preferred logger. An implementantion can be found
on Codeplex: NHibernate.Logging. As some of you might know there
is the Common.Logging logging abstration framework available. Common.Logging
supports several other logging frameworks. So you can use each of them with NHibernate
via Common.Logging.

The following logging frameworks are supported by Common.Logging:

  • System.Console
  • System.Diagnostics.Trace
  • Log4Net 1.2.9
  • Log4Net 1.2.10
  • NLog
  • Enterprise Library 3.1 Logging
  • Enterprise Library 4.1 Logging

To use the Common.Logging 2.0 logging abstraction framework with NHibernate all you
have to do is to copy the following Assemblies to you projects output directory:

  • Common.Logging.dll
  • NHibernate.Logging.CommonLogging.dll

Needless to say that you have to copy your loggers Assembly too.

To enable the log provider you have to add the following lines to your App.config:

<appSettings>
    <add key="nhibernate-logger"
              value="NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, Hibernate.Logging.CommonLogging"/>
</appSettings>

The Common.Logging providers source code and binaries can be found on Codeplex:
NHibernate.Logging. You may try out the provider and send me feedback about it. Have fun. [:)]

Recent Comments

By: Matthias Gernand Posted on 08-17-2010 15:47

The Current available version is built against NH3 Trunk (rev. 5262).

Unfortunately there is no 3.0.0.Alpha2 Tag in the NH3 Repository.

The download contains a demo console app, so you may replace the provided NHibernate.dll

with the version you like and try the demo app.

By: Fabio Maulo Posted on 08-16-2010 18:53
100% of people found this useful

Can I use it with NHibernate 3.0.0.Alpha2 and above or only with the trunk ?

View All
Powered by Community Server (Commercial Edition), by Telligent Systems