Log4net不为NHibernate创建日志文件 [英] Log4net Not Creating Log File For NHibernate

查看:91
本文介绍了Log4net不为NHibernate创建日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一个使用NHibernate的严肃项目,我已经设置了log4net来输出NHibernate生成的sql,但是在运行Web应用程序后,我找不到任何日志文件.

This is my first serious project using NHibernate and I have setup log4net to output the sql generated by NHibernate but after running my web app I cannot find any log files.

该Web应用程序当前正在使用 http://localhost/dispatch 在本地计算机上运行.分发目录是IIS中的一个虚拟目录,指向My Documents/Visual Studio 2008/Projects中的项目文件夹.

This web app is currently being run on my local machine with http://localhost/dispatch. The dispatch directory is a virtual directory in IIS pointing to a project folder in My Documents/Visual Studio 2008/Projects.

这是Web.config的相对部分

Here is the relavent portion of Web.config

<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">
            my connection string
        </property>
        <property name="proxyfactory.factory_class">
            NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
        </property>
        <property name="show_sql">true</property>
    </session-factory>
</hibernate-configuration>

<log4net>
    <appender name="NHibernateFileLog" type="log4net.Appender.FileAppender">
        <file value="logs/nhibernate.txt" />
        <appendToFile value="false" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
        </layout>
    </appender>
    <logger name="NHibernate.SQL" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="NHibernateFileLog"/>
    </logger>
</log4net>

我的Global.asax文件也是如此:

Also my Global.asax file looks like this:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

namespace DispatchBoard {
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication {
        public static void RegisterRoutes(RouteCollection routes) {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start() {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}

请让我知道我在做什么错.我需要查看此输出以调试效率低下的SQL查询.谢谢.

Please let me know what I am doing wrong. I need to see this output to debug an inefficient SQL query. Thanks.

推荐答案

您可能必须在web.config中配置NHibernate.SQL部分,以将其级别设置为DEBUG(而不是INFO).您还缺少NHibernate.Loader.Loader部分

You might have to configure the NHibernate.SQL section in web.config to have it set the level to DEBUG (but not INFO). You also are missing the NHibernate.Loader.Loader section

<logger name="NHibernate.SQL" additivity="false">
      <level value="DEBUG" />
      <appender-ref ref="ConsoleAppender" />
    </logger>
    <!-- 
      NHibernate.Loader.Loader logs diagnostic stuff and SELECTs. 
      You can use either logger, or both, depending on you needs.
    -->
    <logger name="NHibernate.Loader.Loader" additivity="false">
      <level value="INFO" />
      <appender-ref ref="ConsoleAppender" />
    </logger>

此处是对启用NHibernate的SQL日志记录非常有用

Here is a post that's very helpful to enabling SQL logging for NHibernate

这篇关于Log4net不为NHibernate创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆