2012年9月1日 星期六

[C#] log4net 教學及使用範例 - RollingFileAppender

這個Appender會將Log以檔案的方式紀錄到指定的路徑下




<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
 
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <-- Log會寫在程式執行路徑下的Logs\LogFile.txt -->
      <file value="Logs\LogFile.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <!--日期的格式 yyyyMMdd-HHmm:Log會以分來切割資料-->
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="Date:%d%nThreadID:%t%nLevel:%level%nLogger:%logger%nLine:%l%nMessage:%message%nException:%exception%n%n" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>
 
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
 
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
 
</configuration>

沒有留言:

張貼留言