iBatis.Net - 로깅

iBATIS.NET 2008.10.27 11:23

iBatis.Net은 내부적으로 로그를 남기지만 개발자가 보기위해선 출력용 로그 설정을 따로 해주어야만 한다.

우선
"IBatisNet.Common.Logging.Log4Net.dll"을 참조 추가한 후에

App.Config나 Web.Config에 아래 설정을 추가한다.

Web.Config 에서 설정 예제 :

<?xml version="1.0"?>
<configuration>
  <configSections>

    <!-- 시작 iBatis 로깅 설정-->
    <sectionGroup name="iBATIS">
      <section name="logging"
               type="IBatisNet.Common.Logging.ConfigurationSectionHandler,              
                     IBatisNet.Common" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <!-- 종료 iBatis 로깅 설정-->

    중략 ...........
 
  </configSections>

  <!-- 시작 iBatis 로깅 설정-->
  <iBATIS>
    <logging>
      <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
                               IBatisNet.Common.Logging.Log4Net">
        <arg key="configType" value="inline" />
      </logFactoryAdapter>
    </logging>
  </iBATIS>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Logs/log.txt" />
      <param name="MaxSizeRollBackups" value="2" />
      <param name="MaximumFileSize" value="1000KB" />
      <param name="RollingStyle" value="Size" />
      <param name="StaticLogFileName" value="true" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d - %m%n" />
      </layout>
    </appender>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d - %m%n" />
      </layout>
    </appender>
    <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
    <root>
      <level value="DEBUG" />
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>
    <logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.LazyLoadList">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.SqlMapSession">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.Common.Transaction.TransactionScope">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataAccess.DaoSession">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
      <level value="DEBUG" />
    </logger>
  </log4net>
  <!-- 종료 iBatis 로깅 설정-->

  중략 .................

</configuration>




아래는 쿼리문이 로그로 출력된 예제 :

2008-10-27 11:09:42,171 - Adding file [SqlMap.config] to list of watched files.
2008-10-27 11:09:42,234 - Adding file [dao.xml] to list of watched files.
2008-10-27 11:09:42,265 - Statement Id: [select_categories] Prepared SQL: [select  CategoryID,
              CategoryName,
              Description
        from  Categories]
2008-10-27 11:09:42,312 - Statement Id: [select_categories] PreparedStatement : [select  CategoryID,
              CategoryName,
              Description
        from  Categories]
2008-10-27 11:09:42,312 - Cache miss using key '-34371689|9223372034082799388'
2008-10-27 11:09:42,546 - Open Connection "66313729" to "Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0".
2008-10-27 11:09:42,593 - Cache object 'System.Collections.Generic.List`1[WebApp1.Categories]' using key '-34371689|9223372034082799388'
2008-10-27 11:09:42,593 - Close Connection "66313729" to "Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0".
2008-10-27 11:09:58,000 - Statement Id: [select_categories] PreparedStatement : [select  CategoryID,
              CategoryName,
              Description
        from  Categories]
2008-10-27 11:09:58,000 - Retrieved cached object 'System.Collections.Generic.List`1[WebApp1.Categories]' using key '-34371689|9223372034082799388'



Log4Net의 사용법은 이곳을 참조할 것!!!!












tags : ,
Trackback 1 : Comment 0

티스토리 툴바