Logo

NHibernate

The object-relational mapper for .NET

How to

This page is converted from the old nhforge.org Wiki. First published by: mgernand on 08-16-2010, Last revision by: mgernand on 09-27-2010

Using NLog via Common.Logging with NHibernate

The NHibernate 3 Trunk-Version contains a  new Interface "IInternalLogger" 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 and the
corresponding Common.Logging-Provider 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. [:)]

© NHibernate Community 2024