我在解决方案中有其他类库的WCF项目。我使用nuget包管理器为需要记录的项目添加了Common.Logging。
我收到此错误:
无法创建类型 “Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'
当我执行时:
Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger<Service1>();
logger.Error("Test");
我的Web.Config是here
编辑:
Bin文件夹有Common.Logging.Log4net1213.dll以及log4net.dll
答案 0 :(得分:8)
检查您的Common.Logging.Log4net.dll是否已复制到输出目录。在大多数情况下,dll会丢失,因为项目中没有直接引用。
在您的配置中,您有:
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net - &gt;引用您目录中不存在的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>
或者重命名dll