Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4Net and .NET 4.0 RC

I tried to compile a project dependent on the Log4Net logging framework using .NET 4.0 RC and ran into some problems.

Out of the box (just changing the target to .NET 4.0), it no longer works, a security exception is thrown.

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

This was resolved by adding the following line to the log4net assembly(in AssemblyInfo.cs):

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

Can someone explain why this is required and are there alternatives to doing it this way? Is this related to how Log4Net is written or something else?

like image 521
vzczc Avatar asked Feb 17 '10 10:02

vzczc


2 Answers

This is required because .NET 4.0 added Level 2 Security-Transparent Code (which is the new default) and did away with Code Access Security. Level 1 Security-Transparent Code is still there for compatibility but, as you found, has to be specified.

You are correct that it is related to how Log4Net is written. There really is no alternative to the solution you found other than to update the Log4Net code - or switch to a different logging solution :)

like image 183
Nate Pinchot Avatar answered Nov 19 '22 02:11

Nate Pinchot


This error is known as https://issues.apache.org/jira/browse/LOG4NET-347 and it seems to have been fixed.

like image 28
Nachbars Lumpi Avatar answered Nov 19 '22 03:11

Nachbars Lumpi