无法将 Log4Net 与 .net Framework 4 一起使用
我们计划在我们的应用程序中使用 Log4net。但如果目标框架是 4,我无法导入“log4net”命名空间。
我还收到警告 无法解析引用的程序集“log4net”,因为它依赖于“System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”,该依赖项不在当前目标框架“.NETFramework,Version=v4”中.0,配置文件=客户端”。请删除对不在目标框架中的程序集的引用,或考虑重新定位您的项目。
那么这里出了什么问题呢?
注意-如果我将目标框架更改为 3.5,则日志记录可以工作 注意 - 这是一个 Windows 应用程序。
提前致谢。
We are planning to use Log4net in our application . But I am unable to import the "log4net" namespace if the target framework is 4.
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". 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 .
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在项目属性页面上,将目标框架从
.NET Framework 4 Client Profile
更改为.NET Framework 4
On the projects properties page change the target framework from
.NET Framework 4 Client Profile
to.NET Framework 4
请在此处查看答案:
log4net 与 .NET 4.0
See here for your answer:
log4net with .NET 4.0
请参阅此帖子:
Log4Net 和 .NET 4.0
它的答案指向此处的解决方案:
http://krishnabhargav。 blogspot.com/2010/02/using-net-35-clr-20-dll-inside-visual.html
Please see this SO post:
Log4Net and .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
您为什么不打算使用 Nlog?它支持所有最新的 .NET 版本,并且并不比 log4net 差(对我来说甚至更好)。
Why are you not planning to use Nlog? It supports all latest .NET builds and isn't worse then log4net (even better for me).
如果在尝试安装 log4net 时仍然收到“无法找到与目标框架 '.NETFramework,Version=v4.0' 兼容的程序集引用”的信息,即使您的框架指向 4.0,您可能需要更新 NuGet 。
为此,请关闭 Visual Studio 并以管理员身份重新打开它。工具>扩展管理器> NuGet 包管理器 >卸载。
您可能需要重新启动 VS。
当它启动备份时,转到“工具”>“扩展管理器> Online Gallery 并在那里找到 Nuget 并安装它。
然后您应该能够正确安装 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.
To do this, close your Visual Studio and reopen it as administrator. Tools > Extension Manager > NuGet Package Manager > Uninstall.
You will probably need to restart VS.
When it starts back up, go Tools > Extension Manager > Online Gallery and find Nuget there and install it.
You should then be able to install log4net properly.