Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type initializer for 'NHibernate.LoggerProvider' threw an exception

I am trying to use the Common.Logging assembly to replace the default nHibernate Log4net logging.

I added a reference in my project to:
Common.Logging.dll v2.0
NHibernate.Logging.CommonLogging.dll v1.2.0.4000

and then added the following to my Web.config:

<add key="nhibernate-logger" value="NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, Hibernate.Logging.CommonLogging"/>

My ulitmate goal is to replace the Log4net logging with the Enterprise Library 5.0, but I'm just taking it one step at a time at the moment.

When I run my app now I get the following exception:

The type initializer for 'NHibernate.Cfg.Configuration' threw an exception. =>
The type initializer for 'NHibernate.LoggerProvider' threw an exception. =>
The type initializer for 'NHibernate.LoggerProvider' threw an exception. =>
Unable to instantiate: =>
Value cannot be null.\r\nParameter name: type
 at NHibernate.LoggerProvider.LoggerFor(Type type)
 at NHibernate.Cfg.Configuration..cctor()

Is there anything that I'm missing to use the Common.Logging with nHibernate? I've tried following the instructions I've found on the web but it's not working and I can't find a solution :(

I'm using NHibernate v3.2.0.4000.

PS. This is my very first post on this site so sorry if the formatting is not right, I will glady accept constructive criticism :o)

like image 304
user887732 Avatar asked Nov 24 '11 18:11

user887732


2 Answers

switch Hibernate.Logging.CommonLogging with NHibernate.Logging.CommonLogging

like image 160
Firo Avatar answered Oct 14 '22 12:10

Firo


try installing the NHibernate.Logging package from NuGet (or referencing the library, if you don't use NuGet). Worked for me.

Cheers.

like image 37
Tim Avatar answered Oct 14 '22 10:10

Tim