José F. Romaniello

Las aventuras y desventuras de un codificador.

I have created a new package that add support for writing NHibernate logs with NLog.
The package is not a dll but only one class.

In order to use this package, simply install with nuget:

2011-05-04_0838

This is an example app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>
  <appSettings>
    <add key="nhibernate-logger" value="YourNamespace.NLogFactory, YourAssemblyName"/>
  </appSettings>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="ds" xsi:type="Console"/>
    </targets>
    <rules>
      <logger name="NHibernate.SQL" minlevel="Debug" writeTo="ds" />
    </rules>
  </nlog>
</configuration>

Remember to change “YourNamespace” and “YourAssemblyName”. That is all.
You don’t need to run Configure or some initialization code as in log4net.

There is an alternative approach here but it is a little bit more complicated.

| More

1 comentarios:

Hello Jose!

Ping back from http://tillias.wordpress.com/2011/05/04/nhibernate-logging-and-removing-nlog-direct-reference/

I've managed to remove direct reference to NLog there. Can you please update Nuget package please?

Publicar un comentario en la entrada