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

标签 c# wcf log4net log4net-configuration

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

我收到这个错误:

Unable to create type '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 Snapshot of Bin Folder content related to Common.Logging

最佳答案

检查您的 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 -> 引用不在您的目录中的 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

关于c# - 无法创建类型 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30595476/

相关文章:

c# - 在代码隐藏中更改 li 类

c# - Azure 移动服务/Azure 表 : How to handle list of "members"

c# - 在 Linq 中选择 column1 的所有不同的最后记录并按 column2 排序(相应地不工作)

c# - 从 WCF 服务打印 HTML 到网络上的特定打印机

c# - 部署时 Log4Net 不记录

c# - SQL UPDATE 不起作用并且没有抛出错误

c# - 是否可以去掉 Service 类中的 TClient 泛型类型

wcf - 在 Mono 上托管 WCF 的问题

design-patterns - Log4Net Wrapper 类会是什么样子?

c# - 插件 dll 中的 Log4Net 配置?