无法创建类型'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net'

Div*_*Pal 4 c# wcf log4net log4net-configuration

我在解决方案中有其他类库的WCF项目.我使用nuget包管理器为需要记录的项目添加了Common.Logging.

我收到此错误:

无法创建类型'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net'

当我执行时:

Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger<Service1>();
logger.Error("Test");
Run Code Online (Sandbox Code Playgroud)

我的Web.Config就在这里

编辑:Bin文件夹有Common.Logging.Log4net1213.dll以及log4net.dll Bin文件夹内容的快照与Common.Logging相关

Pet*_*ter 8

检查您的Common.Logging.Log4net.dll是否已复制到输出目录.在大多数情况下,dll丢失,因为项目中没有直接引用.

在您的配置中,您有:

<logging>

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

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

  </factoryAdapter>

</logging>
Run Code Online (Sandbox Code Playgroud)

Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net - >引用不在您的目录中的Common.Logging.Log4Net.dll.有一个Common.Logging.Log4Net1213.dll dll.所以你可以将配置更改为:

<logging>

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

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

  </factoryAdapter>

</logging>
Run Code Online (Sandbox Code Playgroud)

或者重命名dll