Log4net记录日志存库并存本地

2/11/2016来源:C#应用人气:2464

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <!--Log4net Begin-->
  <log4net>
    <root>
      <!--控制级别,由低到高: all|debug|info|warn|error|fatal|off-->
      <level value="All"/>
      <appender-ref ref="rollinglogfileappender" />
      <appender-ref ref="consoleappender" />
      <appender-ref ref="adonetappender_MySQL"/>
    </root>
    <!--<logger name="LogWriter">
      <level value="ALL"/>
      <appender-ref ref="ADONetAppender"/>
      <appender-ref ref="RollingLogFileAppender" />
    </logger>-->
    <appender name="AdoNetAppender_MySql" type="log4net.Appender.ADONetAppender">
      <bufferSize value="1" />
      <connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
      <connectionString value="server=172.16.13.165;user id=microask;pwd=123456;port=3306;pooling=True;database=microask2" PRoviderName="MySql.Data.MySqlClient;" />
      <commandText value=" INSERT INTO t_system_log (Date1,Thread,Level,Logger,Message,Exception) VALUES (@Date1, @Thread, @Level, @Logger, @Message, @Exception)" />
      <parameter>
        <parameterName value="@Date1" />
        <dbType value="String" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@Thread" />
        <dbType value="String" />
        <size value="100" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@Level" />
        <dbType value="String" />
        <size value="100" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@Logger" />
        <dbType value="String" />
        <size value="100" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@Message" />
        <dbType value="String" />
        <size value="1000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@Exception" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>
    <!-- setup the root category, add the appenders and set the default level -->

    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Log\\后台log.txt" />
      <param name="AppendToFile" value="true" />
      <param name="RollingStyle" value="Date" />
      <param name="DatePattern" value="yyyyMMdd" />
      <param name="StaticLogFileName" value="true" />

      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
        <param name="Header" value="-----------------------header--------------------------" />
        <param name="Footer" value="-----------------------footer--------------------------" />
      </layout>
    </appender>

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
      </layout>
    </appender>
    <!-- Setup the root category, add the appenders and set the default level -->



  </log4net>
  <!--Log4net End-->
</configuration>