简体   繁体   English

nHibernate Log4Net日志记录异常

[英]nHibernate Log4Net logging exception

I have a project, fully setup and tested successfully with nHibernate that I am trying to run in debug mode with Visual Studio 2010. Running the project prior to setting up log4net obviously runs fine, but adding the reference to the log4net assembly, the appropriate lines int web\\Global.Asax file, and the configuration parameters in the web.config file result in the following error 我有一个项目,使用nHibernate成功完成设置和测试,我试图在Visual Studio 2010的调试模式下运行。在设置log4net之前运行项目显然运行正常,但添加对log4net程序集的引用,相应的行int web \\ Global.Asax文件以及web.config文件中的配置参数导致以下错误

Inheritance security rules violated while overriding member: 'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. 覆盖成员时违反了继承安全规则:'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 line 在线

Configuration configuration = new Configuration().Configure(); 配置配置= new Configuration()。Configure();

in the following block of code 在下面的代码块中

public static ISessionFactory SessionFactory;
    public static ISession OpenSession()
    {
        if (SessionFactory == null) //not threadsafe
        { //SessionFactories are expensive, create only once
            Configuration configuration = new Configuration().Configure();
            configuration.AddAssembly(Assembly.GetCallingAssembly());
            SessionFactory = configuration.BuildSessionFactory();
        }
        return SessionFactory.OpenSession();
    }

I am explicity following this guide: Configure Log4Net for use with NHibernate from the nHibernate project. 我明确遵循本指南:从nHibernate项目配置Log4Net以与NHibernate一起使用

您需要在log4net源中的Util.ReadOnlyPropertiesDictionary.GetObjectData中添加SecurityCritical属性,详见https://stackoverflow.com/a/2977020/43846

You should download version 1.2.11 of log4net. 你应该下载log4net的1.2.11版。 It includes an assembly targetting .NET 4.0 which contains many more fixed than just that one attribute. 它包括一个针对.NET 4.0的程序集,它包含许多固定而不仅仅是那个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM