简体   繁体   English

无法将Log4Net与.net Framework 4一起使用

[英]Unable to use Log4Net with .net Framework 4

We are planning to use Log4net in our application . 我们计划在我们的应用程序中使用Log4net。 But I am unable to import the "log4net" namespace if the target framework is 4. 但是如果目标框架是4,我无法导入“log4net”命名空间。

I also get a warning 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". 我也收到警告引用的程序集“log4net”无法解析,因为它依赖于“System.Web,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”,它不在当前目标框架中“。 NETFramework,版本= V4.0,外形=客户”。 Please remove references to assemblies not in the targeted framework or consider retargeting your project. 请删除不在目标框架中的程序集的引用或考虑重新定位项目。

So what is going wrong here ? 那么这里出了什么问题?

Note-Logging works if I change the target framework to 3.5 Note-This is a windows application . 注意 - 日志工作如果我将目标框架更改为3.5注意 - 这是一个Windows应用程序。

Thanks in Advance. 提前致谢。

在项目属性页面上,将目标框架从.NET Framework 4 Client Profile更改为.NET Framework 4

See here for your answer: 看到这里的答案:

log4net with .NET 4.0 log4net与.NET 4.0

Please see this SO post: Log4Net and .NET 4.0 请看这篇SO帖子: Log4Net和.NET 4.0

It has an answer that points to a solution here: http://krishnabhargav.blogspot.com/2010/02/using-net-35-clr-20-dll-inside-visual.html 它的答案指向一个解决方案: http//krishnabhargav.blogspot.com/2010/02/using-net-35-clr-20-dll-inside-visual.html

Why are you not planning to use Nlog? 你为什么不打算使用Nlog? It supports all latest .NET builds and isn't worse then log4net (even better for me). 它支持所有最新的.NET版本,并不比log4net差(对我来说更好)。

If you are still getting the "Unable to find assembly references that are compatible with the target framework '.NETFramework,Version=v4.0'" when trying to install log4net even though your framework is pointing to 4.0, you probably need to update NuGet. 如果你仍然在尝试安装log4net时“无法找到与目标框架'.NETFramework兼容的程序集引用,版本= v4.0'”,即使你的框架指向4.0,你可能还需要更新NuGet 。

To do this, close your Visual Studio and reopen it as administrator. 为此,请关闭Visual Studio并以管理员身份重新打开它。 Tools > Extension Manager > NuGet Package Manager > Uninstall. 工具> Extension Manager> NuGet包管理器>卸载。

You will probably need to restart VS. 您可能需要重新启动VS.

When it starts back up, go Tools > Extension Manager > Online Gallery and find Nuget there and install it. 当它开始备份时,转到工具>扩展管理器>在线图库并在那里找到Nuget并安装它。

You should then be able to install log4net properly. 然后,您应该能够正确安装log4net。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM