• 用Log4Net记录NHibernate中执行的SQL语句及执行时间


    首页,在web.config中加入以下配置:

    <configuration>
       <configSections>
         <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
       </configSections>
       <!--log4net 配置-->
       <log4net debug="true">
         <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
           <param name="File" value="log/log.txt"/>
           <param name="AppendToFile" value="false"/>
           <param name="RollingStyle" value="Date"/>
           <param name="StaticLogFileName" value="true"/>
           <layout type="log4net.Layout.PatternLayout">
             <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
           </layout>
         </appender>
         
         <logger name="NHibernate" additivity="true">
           <level value="ERROR"/>
           <appender-ref ref="DebugAppender" />
         </logger>
         <logger name="NHibernate.SQL" additivity="true">
           <level value="DEBUG"/>
           <appender-ref ref="DebugAppender" />
         </logger>
         
         <logger name="NHibernate.AdoNet.AbstractBatcher" additivity="true">
           <level value="DEBUG"/>
           <appender-ref ref="DebugAppender" />
         </logger>
         
         <root>
           <!-- levels: DEBUG, INFO, WARN, ERROR, FATAL -->
           <level value="DEBUG"/>
           <appender-ref ref="rollingFile"/>
         </root>
       </log4net>
     </configuration>

    然后,在Global.asax加入以下代码并添加相应引用:

     1 private static log4net.ILog logger = log4net.LogManager.GetLogger("Logger");
     2 
     3 private static readonly ILog applicationInfoLog = LogManager.GetLogger("ApplicationInfoLog");
     4 
     5 protected override void Application_Start(object sender, EventArgs e)
     6 {
     7 //初始化log4net
     8 log4net.Config.XmlConfigurator.Configure();
     9 
    10 base.Application_Start(sender, e);
    11 
    12 }
  • 相关阅读:
    Sky中国War3的旗帜
    2008流行趋势发布暨07届学生毕业秀(上海大学主办)
    随便写一下
    六一节——小朋友们快乐
    HEI
    Update my blog to improve my idea.
    由ipod引起的奇遇记
    加勒比海盗
    “老板娘”请客吃饭
    蚂蚁工坊
  • 原文地址:https://www.cnblogs.com/jxcia_Lai/p/3511247.html
Copyright © 2020-2023  润新知