开发者

log4net and .net Framework 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' th开发者_Go百科rew 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.


I've found a compiled version of log4net for .NET client profile here:

http://gosheg.blogspot.com/2011/04/log4net-in-net-40-c-applications-net.html


This worked for me:

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

There might be some other things you'll need to do to get it to build for the 4.0 framework.

See this post:

Weird override problem with Fluent NHibernate and .NET 4


I have fixed the similar issue by simply updating the Log4Net package from Visual Studio package manager.

Thanks, Khachatur


I Fixed it by adding [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)] to log4net AssemblyInfo but now its not logging

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜