I remember the days (not too long ago, really) when log4net came along with NH and was compulsory for the OR-Mapper. Nowadays it isn’t compulsory anymore, but optional.
I really wonder how this is achieved by NHibernate. If anyone could explain in a few words, that would be highly appreciated!
NHibernate has an ILoggerFactory to create the logger defined as below:
The
IInternalLoggerinterface, that depites the name is not internal at all, is the actual logger interface, that non surprisingly map exactly theILoginterface oflog4net. NH internally ask logger factory when it needs to log. If no other logger is configured, and log4net assembly is present, the factory return a wrapper around log4net. If you want provide your own you just need to provide a logger factory and configure it as:As you guess, the class MyLoggingLoggerFactory must implement
ILoggerFactory. The returned loggers of course must implementIInternalLogger, that as said before is public even if the unhappy name can be misleading.This is the startegy they use to be
log4netindependent. As an addition, if you don’t want log at all, just remove the log4net assembly from your deploy directory: NH will degrade gracefully and use internally a null logger.