Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'

Divesh Pal picture Divesh Pal · Jun 2, 2015 · Viewed 7.9k times · Source

I have WCF project with other class libraries in a solution. I added Common.Logging using nuget package manager for projects which require logging.

I am getting this error :

Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'

when I excute :

Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger<Service1>();
logger.Error("Test");

My Web.Config is here

EDIT : Bin Folder have Common.Logging.Log4net1213.dll as well as log4net.dll Snapshot of Bin Folder content related to Common.Logging

Answer

Peter picture Peter · Jun 2, 2015

Check if your Common.Logging.Log4net.dll is copied to your output directory. In most cases the dll is missing because there is no direct reference in the project.

In your config you have:

<logging>

  <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">

    <arg key="configType" value="INLINE" />

  </factoryAdapter>

</logging>

Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net -> references the Common.Logging.Log4Net.dll which is not in your directory. There is a Common.Logging.Log4Net1213.dll dll. So you can change the config to:

<logging>

  <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">

    <arg key="configType" value="INLINE" />

  </factoryAdapter>

</logging>

Or rename the dll