log4net的和.NET Framework 4.0 [英] log4net and .net Framework 4.0

查看:246
本文介绍了log4net的和.NET Framework 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是有在log4net的问题时,我更新了我的解决方案,以.NET 4.0,然后我下载了它的源代码,并内置log4net的和有针对性的到.NET 4.0,并在我的项目中使用它。

起初,当我提到log4net的是有针对性的运行时间2.0它遵守并运行应用程序,但日志没有工作。

现在,当我运行我的项目,log4net的有针对性的.NET 4.0,我得到错误的类型初始Log4NetTest.TestLog'引发了异常。

不知道如何解决此问题?

编辑:这是内部异常:

的InnerException:同时覆盖件System.TypeLoadException消息=继承安全规则违反:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)。
压倒一切的方法必须与方法的安全辅助功能相匹配的安全访问被覆盖。
  来源= log4net的
  TypeName=log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
  堆栈跟踪:
    在log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory的LoggerFactory)
    在log4net.Repository.Hierarchy.Hierarchy..ctor()在C:\ SRC \库\层次\ Hierarchy.cs:行150

解决方案
  

在log4net的源$ C ​​$ C,添加[SecurityCritical]属性的   Util.ReadOnlyPropertiesDictionary.GetObjectData方法和构建。

刚刚编译源目标框架4.0(而不是客户端)。来源$ C ​​$的1.2.11 C版已经包含了此属性,但一定要使用NET_4_0'作为一个编译器参数。否则,此属性将不会加入。

I was having issues in log4net when I updated my solutions to .net 4.0 , and then I downloaded the source of it and built log4net and targeted it to .net 4.0 and used it in my projects.

Initially when I referred log4net that is targeted to run time 2.0 it complied and run the application but log did not work.

Now when I run my project with log4net targeted to .net 4.0 I get the error "The type initializer for 'Log4NetTest.TestLog' threw an exception."

Any Idea how to solve this?

Edit: this is the inner exception:

InnerException: System.TypeLoadException Message=Inheritance security rules violated while overriding member:  
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.  
Security accessibility of the overriding method must match the security accessibility of the method being overriden.
  Source=log4net
  TypeName=log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
  StackTrace:
    at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
    at log4net.Repository.Hierarchy.Hierarchy..ctor() in C:\src\Repository\Hierarchy\Hierarchy.cs:line 150

解决方案

In the log4net source code, add a [SecurityCritical] attribute to the Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.

Just compiled the source for target framework 4.0 (not client). Source code of version 1.2.11 already contains this attribute, but be sure to use 'NET_4_0' as a compiler argument. Otherwise, this attribute will not be added.

这篇关于log4net的和.NET Framework 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆