c# - Log4net 引用程序集依赖问题

标签 c# .net log4net

<分区>

我是一名 Java 开发人员,刚开始学习 C# 来开发几个项目。我很高兴看到我习惯使用的许多 Java 框架(log4j、ant、hibernate 等)都有它们的 .net 版本(log4net、nant、nhibernate)。

我刚刚创建了一个项目并尝试将 log4net 程序集引用放入其中,但我收到以下警告(随后是 4 个错误,提示无法识别 log4net 命名空间和类):

The referenced assembly "log4net" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

我添加了对 System.Web.ApplicationServicesSystem.Web.Services 的引用,但它不起作用。对于解决此依赖性问题的任何帮助,我们将不胜感激。

谢谢

最佳答案

更新:

如果您仍然收到此错误,则说明您使用的是过时版本的 log4net,您应该考虑更新到 current version ,它不需要完整的 .NET 4.0 框架。感谢@Philippe感谢您在评论中指出这一点。


您的项目正在引用不包括 System.Web 的 .NET 4.0 客户端配置文件;您实际上需要引用完整框架。

参见 How To: Target a Specific .NET Framework Version or Profile在 MSDN 上获取指导。

  1. In Visual Studio, open the project you want to change.
  2. Right-click the project in Solution Explorer and then click Properties.
  3. In the Project Designer, locate the Target Framework list, as follows.

    • For Visual Basic projects, click the Compile tab and then click Advanced Compile Options. The Target Framework list is in the Advanced Compiler Settings dialog box.
    • For Visual C# projects, the Target Framework list is on the Application tab of the Project Designer. For more information, see Application Page, Project Designer (C#).
    • For Visual F# projects, the Target Framework list is on the Application tab of the Project Designer.
  4. In the Target Framework list, select the .NET Framework version or profile that you want. When you click OK, the project unloads and then reloads in the integrated development environment (IDE). The project now targets the .NET Framework version that you just selected.

可能还感兴趣的是 Troubleshooting .NET Framework Targeting Errors .

关于c# - Log4net 引用程序集依赖问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4518585/

相关文章:

c# - 将 KeyVault secret 传递给 VSTS 中的 .net core 2 xUnit/MsTest

c# - log4net什么时候登录?

c# - 对 Func<T> 进行泛型类型约束

C# HttpWebRequest 与 WebRequest

c# - 我如何获得我与 Spring.NET IoC 的依赖关系的图形表示?

c# - Prism 实际上为开发人员提供了什么?值得吗?

c# - 防止加载 DataGridView RowEnter 事件

c# - .NET Parallel.ForEach、StreamWriter 输出 + 线程安全

c# - 如何在代码中而不是在 xml 文件中使用 log4net 配置 NHibernate 日志记录?

log4net - 使用 OWIN 中间件或委托(delegate) MessgaeHandler 来记录 api 请求/响应?