1

I upgraded my WinForms project to NH 3.2, and saw somewhere that it no longer requires Log4net to produce logging info.

Is this correct?

I now need to turn on logging, but I've been unable to find that reference again.

How do you enable logging in NH 3.2?

I'm not currently using a config file - if that's a requirement, please provide a sample.

Also, I prefer to log to the Visual Studio Output window, but anything that works is fine.

4
  • Have a look at this answer on SO:- stackoverflow.com/q/474659/29467 Commented Nov 14, 2011 at 23:30
  • Also look at nhlogging.codeplex.com and nhforge.org/wikis/howtonh/… Commented Nov 14, 2011 at 23:33
  • @Nathan - thanks for the links. So it seems I still need an external logging framework if I want to see anything more than the generated SQL, correct? Sigh. In view of my own bad experience with Log4net, and the dozens of other people who seem to have had similar problems, this is not good news... Commented Nov 16, 2011 at 21:35
  • Well if you use nhlogging you can use a variety of logging packages. the nuget package is NHibernate.Logging. this should give you access to most of the common logging frameworks. Sorry to hear about your log4net experience. I haven't had any problems with it TBH, but my logging needs have been pertty basic. Commented Nov 16, 2011 at 23:05

1 Answer 1

1

I may have been unduly harsh on log4net...

More than a year ago, I had set it up, adding a section in my app.config file, as suggested in all the blog posts I had read.

It worked for me briefly, and then mysteriously stopped working. There are many, many questions on SO describing similar unpleasant experiences.

Have not needed it since then, so ripped the dll and config out of my project in disgust.

Though I'm certain I've tried this before, and that it silently failed to do any logging whatsoever, I added the following single line back to my code:

log4net.Config.BasicConfigurator.Configure();

and lo and behold, it started logging to the VS Output window, just like I wanted.

So it appears there's no need to configure it at all for simple applications - it does the right thing by default. Presumably, it's the complex configuration that trips people up - it seems far too easy to mess things up.

1
  • 1
    Everybody discussing config files (not where they should be put, what the name would be etc...) and web.config files for ASP. Dead wiki links of NHiberate... So frustrating! While all there is to do to have some kind of logging is this one liner. thanks. Commented Sep 3, 2013 at 5:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.