我在VS2010中创建了一个简单的.NET 4 Web应用程序,并添加了对log4net 1.2.11.0(最新)的引用.
在这个项目中,我做了一个Logger课程(见本文末尾).当我在完全信任环境中调用此类Logger(Logger.Fatal("Test");)时,一切正常.但是,当我将信任级别更改为高(或中)时,它会失败并出现以下异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: 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.
at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
at log4net.Repository.Hierarchy.Hierarchy..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, …Run Code Online (Sandbox Code Playgroud)