Log4net and .net Framework 4.0

I had problems with log4net when I updated my .net 4.0 solutions and then downloaded the source code and created log4net and targeted it to .net 4.0 and used it in my projects.

Initially, when I referenced log4net, which was aimed at runtime 2.0, it ran and ran the application, but the log did not work.

Now when I run my project using log4net targeting .net 4.0, I get an error "The type initializer for 'Log4NetTest.TestLog' threw an exception."

Any idea how to solve this?

Edit: this is an internal 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
+3
source share
5 answers

In the log4net source code, add the [SecurityCritical] attribute to the Util.ReadOnlyPropertiesDictionary.GetObjectData Method and its assembly.

4.0 ( ). 1.2.11 , "NET_4_0" . .

+4

:

log4net [SecurityCritical] Util.ReadOnlyPropertiesDictionary.GetObjectData .

, , 4.0.

:

Fluent NHibernate .NET 4

+2
source

I fixed a similar problem by simply updating the Log4Net package from the Visual Studio Package Manager.

Thanks, Khachatur

0
source

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

0
source

Source: https://habr.com/ru/post/1746987/


All Articles