2012年9月1日 星期六

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


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  
  <log4net>
    <!--
    This use SMTP to send mail.
    -->
    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
      <to value="收件者Mail" />
      <from value="寄件者Mail" />
      <!-- 是否使用SSL加密 -->
      <EnableSsl value="true" />
      <username value="寄件者帳號" />
      <password value="寄件者密碼" />
      <subject value="主旨" />
      <!-- smtpHost 在此是以google的為範例 -->
      <smtpHost value="smtp.gmail.com" />
      <authentication value="Basic" />
      <port value="25" />
      <bufferSize value="512" />
      <lossy value="true" />
      <evaluator type="log4net.Core.LevelEvaluator,log4net">
        <threshold value="ERROR" />
      </evaluator>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="LogName:%c%nLevel:%level%nData:%date%nThreadID:%thread%nMSG:%message%nEX:%exception%n%n" />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="WARN"/>
        <levelMax value="FATAL"/>
      </filter>
    </appender>
    
    <root>
      <level value="ALL" />
      <appender-ref ref="SmtpAppender" />
    </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>

沒有留言:

張貼留言