log4net 사용 관련 요점 집합

6733 단어 log
1.log 를 쓰기 전에 설정 문 서 를 초기 화해 야 합 니 다.관련 코드 는 다음 과 같 습 니 다.
 
log4net.Config.XmlConfigurator.Configure(); //    



log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath("../Log4Net.config")));
 

2.파일 샘플 설정
Log4net.config       :

<?xml version="1.0" encoding="utf-8"?>

<log4net>

  <logger name="KangarooLog">

    <!--control log level: ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF-->

    <!--      LEVEL  ,    DEBUG-->

    <level value="ALL" />

    <!--<appender-ref ref="SmtpAppenderKangaroo"></appender-ref>-->

    <appender-ref ref="FileAppenderKangaroo"></appender-ref>

  </logger>

  <appender name="SmtpAppenderKangaroo" type="log4net.Appender.SmtpAppender">

    <to value="[email protected]"></to>

    <from value="[email protected]" />

    <subject value="Kangaroo Log Message" />

    <smtpHost value="smtp.800best.com" />

    <username value="Kangaroo" />

    <password value="Kangaroo" />

    <bufferSize value="2048" />

    <!--        -->

    <lossy value="false" />

    <!--evaluator    ,   ,   filter  -->

    <!--<evaluator type="log4net.Core.LevelEvaluator">

      <threshold value="ERROR"/>

    </evaluator>-->

    <!--<evaluator type="log4net.Core.LevelEvaluator,log4net">

      <threshold value="WARN" />

    </evaluator>-->

    <!--        -->

    <!--<filter type="log4net.Filter.DenyAllFilter" />-->

    <!--            -->

    <filter type="log4net.Filter.LevelRangeFilter">

      <param name="LevelMin" value="ALL" />

      <param name="LevelMax" value="OFF" />

    </filter>

    <layout type="log4net.Layout.PatternLayout">

      <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] : %newline%message%newline" />

    </layout>

  </appender>

 

 <appender name="FileAppenderKangaroo" type="log4net.Appender.RollingFileAppender">

    <!--    -->

    <!--<file value="D:\KangarooLog.txt"></file>-->

    <param name="File" value="./Log/KangarooLog.log" />

    <param name="AppendToFile" value="true" />

    <!--    ,        -->

    <!--         ,               -->

    <!--<file value="./Log/Kangaroo.txt"></file>-->

    <!--         Log,        -->

    <!--     ,      ,            -->

    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

    <appendToFile value="true" />

    <!--   :Once|Size|Date|Composite-->

    <!--Composite Size Date   -->

    <rollingStyle value="composite" />

    <!--      ,     -->

    <!--rollingStyle   Date ,       -->

    <!--rollingStyle   Size ,   value   -->

    <!--rollingStyle   Composite ,   value   -->

    <maxSizeRollBackups value="10" />

    <!--      ,        -->

    <!--   *.txt , :AX.txt_2008-07-24.PxP           bug-->

    <!--   *.TXT , :AX.txt_2008-07-25.TXT-->

    <datePattern value="_yyyy-MM-dd.TXT" />

    <!--     :KB|MB|GB-->

    <!--      ,           -->

    <maximumFileSize value="2MB" />

    <!--  true,            file     -->

    <staticLogFileName value="true" />

    <!--     INFO ERROR     -->

    <filter type="log4net.Filter.LevelRangeFilter">

      <param name="LevelMin" value="INFO" />

      <param name="LevelMax" value="ERROR" />

    </filter>

    <!--       ,       WARN,             -->

    <filter type="log4net.Filter.LevelMatchFilter">

      <param name="LevelToMatch" value="WARN" />

    </filter>

    <filter type="log4net.Filter.DenyAllFilter" />

    <layout type="log4net.Layout.PatternLayout">

      <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />

    </layout>

  </appender>

</log4net>

3.layot 노드 의 설정 설명
<!--                                                                        Made By AX      -->

<!--        %m(message):       , ILog.Debug(…)                                 -->

<!--        %n(new line):                                                                     -->

<!--        %d(datetime):                                                            -->

<!--        %r(run time):                                                 -->

<!--        %t(thread id):         ID                                                  -->

<!--        %p(priority):          , DEBUG、INFO、WARN…                            -->

<!--        %c(class):         ,  :                                                -->

<!--                     :%-10c -%m%n                                                    -->

<!--                  :                                                                     -->

<!--        ILog log=LogManager.GetLogger(“Exam.Log”);                                        -->

<!--        log.Debug(“Hello”);                                                               -->

<!--                     :                                                            -->

<!--        Exam.Log       - Hello                                                              -->

<!--        %L:                                                                       -->

<!--        %F:                                                                      -->

<!--        %-  :         ,    ,                                        -->

<!--          ,     %r [%t]%-5p %c - %m%n   PatternLayout              : -->

<!--        176 [main] INFO  org.foo.Bar - Located nearest gas station.                         -->

4.유용 한 연결:
하나
로그 유지 소감

좋은 웹페이지 즐겨찾기