Search code examples
nhibernatenlogfluent-nhibernate-mapping

NHibernate + fluent mapping + NLog = No mapped documents found in assembly


I've successfully used the CommonLogging layer in NHibernate to log its internal messages using NLog for previous projects which were using hbm.xml files. I'm now switching to fluent mapping, and the NHibernate logs now only contain one line:

[Log entry: Warn] 2019-02-01 13:30:42.5537 No mapped documents found in assembly: <assembly name>

I also tried to move the nhibernate-logger configuration directive from the App.config file to the code, just after configuring the mapping – and I'm receiving the same warning as before:

var dbCfg = new Configuration();
dbCfg.Configure();
dbCfg = Fluently.Configure(dbCfg)
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<RetailerMapping>())
    .ExposeConfiguration(c =>
    {
        c.SetProperty(@"nhibernate-logger", @"NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, NHibernate.Logging.CommonLogging");
    })
    .BuildConfiguration();
dbCfg.AddAssembly(Assembly.GetExecutingAssembly().GetName().Name);

What am I doing wrong?


Solution

  • Ok, I'm quite embarrassed by this, and I was tempted to delete the question altogether, but I decided to post the solution just in case some other airhead hits the same snag: I had forgotten to remove the minLevel directive from the NLog configuration, and I was only logging warnings, errors and fatal errors – and that warning made me think it wasn't logging because of the warning, when in fact it wasn't logging because I had inhibited lower level messages.