반응형

 

 

 

프로젝트의 App.config 파일에 log4net 설정 추가

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <log4net>

    <root>
      <level value="ALL" />
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="ConsoleLog" />
    </root>

    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <file value="Log\" />
      <datePattern value="yyyy-MM-dd'.log'" />
      <staticLogFileName value="false" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="5MB" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{HH:mm:ss.fff} [%thread] %-5level %logger : %message %newline" />
        <conversionPattern value="%date{HH:mm:ss.fff} [%thread] %-5level : %message %newline" />
      </layout>
    </appender>

    <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
      <filter type="log4net.Filter.LevelRangeFilter">
        <level value="INFO" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%date{HH:mm:ss.fff} [%thread] %-5level : %message [%stacktrace{level}]%newline" />
        <param name="ConversionPattern" value="%date{HH:mm:ss.fff} [%thread] %-5level : %message%newline" />
      </layout>
    </appender>

  </log4net>
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>

</configuration>

 

 

 

반응형

+ Recent posts