设置NHibernate时出现多个错误(log4net,配置)

时间:2014-07-23 09:09:43

标签: c# nhibernate log4net

我正在尝试从教程here为Web应用程序设置NHibernate。在代码中的某一点,有两行如下。

        Configuration cfg = new Configuration();
        cfg.Configure();

cfg.Configure()我收到错误 未声明'log4net'元素。 。谷歌搜索后,我尝试了一个单独的 log4net.config 并按照建议从Xml-> Schemas设置xsd,但它没有用。我目前有一个 hibernate.cfg.xml ,如下所示。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <!-- NHibernate Section -->
    <section
        name="hibernate-configuration"
        type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate"
    />

    <!-- Log4Net Section -->
    <section
        name="log4net"
        type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
    />
</configSections>

<connectionStrings>
    <add name="db" connectionString="Data Source=....;Persist Security Info=True;User ID=...;Password=....;Pooling=False;"/>
</connectionStrings>
<!-- NHibernate Configuration -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">
            NHibernate.Connection.DriverConnectionProvider
        </property>
        <property name="dialect">
            NHibernate.Dialect.MsSql2008Dialect
        </property>
        <property name="connection.driver_class">
            NHibernate.Driver.SqlClientDriver
        </property>
        <property name="connection.connection_string">
            db
        </property>
        <property name="proxyfactory.factory_class">
            NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
        </property>
    </session-factory>
</hibernate-configuration>


<!-- Log4Net Configuration -->
<log4net>

    <!-- Define an output appender (where the logs can go) -->
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
        <param name="File" value="log.txt" />
        <param name="AppendToFile" value="true" />
        <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
        </layout>
    </appender>

    <!-- Note: Priority level can be ALL/DEBUG/INFO/WARN/ERROR/FATAL/OFF -->
    <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
    <root>
        <priority value="WARN" />
        <appender-ref ref="LogFileAppender" />
    </root>
</log4net>

0 个答案:

没有答案