4

I'm having issues with some vague errors popping out of my fluent configuration. I have read that setting up a logging solution will help me zero in on the issue. I would like to use NLog. I understand that I need to use Common.Logging 2.0 and NHibernate.IInterfaceLogger to get it up and running. I'm just not sure how to put the pieces together. My system is based off of the Onion Architecture. I have my Logging service set up for NLog and I have my interface for it, but I'm just a bit confused on where I should bind all of this together. My Fluent NHibernate configuration exists in my Data project. I'm assuming I would want to bind all of this together there.

Any thoughts on this would be awesome! I'm a little lost!

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
Tyler Wright
  • 795
  • 1
  • 9
  • 28
  • 1
    not sure about NLog. but as soon as you add log4net to references and configure. NHibernate will love to use it. go for log4net. should be the preferable logger IMO. – DarthVader Jun 12 '12 at 17:26
  • 1
    log4net support is embedded in NH, but many people have a lot of trouble configuring it - I certainly did. NLog looks a lot simpler, based on the answers below (have not tried it myself...yet). – Tom Bushell Jun 13 '12 at 15:00

1 Answers1

6

NHibernate.NLog nuget package does this. I use it in a project now.

For the sake of completeness or if that package ever disappears or the user doesn't use nuget. You add this to your FluentConfiguration:

.ExposeConfiguration(c =>
    {
        c.SetProperty(@"nhibernate-logger", @"Microfilm.Core.NLogFactory, Microfilm.Core");
    })

Implement ILoggerFactory to return a class that implements IInternalLogger. It's pretty straightforward what to include in the IInternalLogger methods; you're just bridging the calls for the NHibernate logger to NLog calls.

hometoast
  • 11,522
  • 5
  • 41
  • 58
  • Did you test this with Fluent Configuration? It doesn't work for me and the source code of `NHibernate.LoggerProvider` shows that it gets the class of the logger factory from the app settings exclusivly. There is no fall back to the NHibernate configuration, so `config.SetProperty` can't possibly work. – Daniel Hilgarth Jul 16 '12 at 17:43
  • That bit about `.ExposeConfiguration` *is* FluentNHibernate. I'm using FluentNHibernate v1.3 and NHibernate 3.2 – hometoast Jul 17 '12 at 11:07
  • As mentioned in some other posts, the ExposeConfiguration did nothing for me. But I added this to the appSettings in the web.config and it worked fine: – Papa Burgundy Feb 04 '14 at 23:24
  • 1
    I'm curious to know why the .ExposeConfiguration doesn't work for some. It's a method in the FluentConfiguration class – hometoast Feb 06 '14 at 19:56