알뜰살뜰 정보/C#

log4net 설정

쉬고싶은 거북이 2021. 5. 24. 01:31
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="LogFile" type="log4net.Appender.RollingFileAppender">
    <file value="../../log/MainLog.txt" />
    <staticLogFileName value="true" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date  - %message%newline" />
    </layout>
  </appender>
  <appender name="ErrorFile" type="log4net.Appender.RollingFileAppender">
    <file value="../../log/ErrorLog.txt" />
    <staticLogFileName value="true" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <filter type="log4net.Filter.LevelRangeFilter">
      <param name="LevelMin" value="Error" />
      <param name="LevelMax" value="Error" />
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="ALL" />
    <appender-ref ref="LogFile" />
    <appender-ref ref="ErrorFile" />
  </root>
</log4net>


일반 로그와 에러로그 파일 생성 설정
<!--
#03 : 로그 파일은 일정 크기를 넘으면 가장 오래된 내용을 삭제하는 방식으로 관리함
#04 : 로그 파일의 이름은 logTest.txt로 함
#05 : 로그 파일 유지 
#06 : 일정 크기를 넘었을때 가장 오래된 내용이 파일이라도 삭제하겠음
#07 : 로그 파일 관리 단위는 파일 크기로 함
#08 : 최대로 백업할 로그 파일의 갯수 = 10개
#09 : 로그 파일 최대 크기 = 1MB
#10 : 로그 패턴
#11 : 로그가 작성될 시간 - 로그내용 NewLine
#21 : 로그 파일에 기록할 로그 범위를 필터로 나눴음
-->