Extensible as it is, it's no wonder that NHibernate also supports injecting custom loggers. The support is twofold:
- There's the ILoggerFactory interface, that must be implemented by custom logger factories; this is the responsible for creating actual loggers;
- Then there's the IInternalLogger interface, the one that provides the common functions found in most loggers (warn, info, debug, error, fatal, etc).
By default, it uses Log4Net, but it is easy to add our own logger.
So, let's start by implementing a logger factory - just the skeleton, I leave it to you as an exercise:
And then the actual logger:
Remember, this is just a skeleton, do implement these methods anyway you like.
Now, all that is left is the registration:
And NHibernate will start logging using your logger!
PS - Issue NH-3776 is an attempt to make using logger factories even simpler and in a similar fashion to other pluggable features.