asp.NetMVCログプラグインLog 4 Net学習ノート2:sqlserverにログを保存する構成

7644 ワード

1.sqlserverの構成に書きます.
<!--   SQLSERVER     -->

  <log4net>

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">

      <!--<bufferSize value="10" />-->

      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

      <connectionString value="Server=localhost;UID=sa;PWD=8086;DataBase=daohang360;Max Pool Size=1000"/>

      <commandText value="INSERT INTO Log VALUES ([Date],[Thread],[Level],[Logger],[Message],[Exception]) (@log_date, @thread, @log_level, @logger, @message, @exception)" />

      <parameter>

        <parameterName value="@log_date" />

        <dbType value="DateTime" />

        <layout type="log4net.Layout.RawTimeStampLayout" />

      </parameter>

      <parameter>

        <parameterName value="@thread" />

        <dbType value="String" />

        <size value="255" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%thread" />

        </layout>

      </parameter>

      <parameter>

        <parameterName value="@log_level" />

        <dbType value="String" />

        <size value="50" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%level" />

        </layout>

      </parameter>

      <parameter>

        <parameterName value="@logger" />

        <dbType value="String" />

        <size value="255" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%logger" />

        </layout>

      </parameter>

      <parameter>

        <parameterName value="@message" />

        <dbType value="String" />

        <size value="4000" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%message" />

        </layout>

      </parameter>

      <parameter>

        <parameterName value="@exception" />

        <dbType value="String" />

        <size value="2000" />

        <layout type="log4net.Layout.ExceptionLayout" />

      </parameter>

    </appender>

    <root>

      <!-- Set this to "ERROR" before release -->

      <!--Highest: OFF->FATAL->RROR->WARN->INFO->DEBUG->ALL :Lowest -->

      <level value="ALL" />

      <appender-ref ref="AdoNetAppender" />

      <!-- <appender-ref ref="SmtpAppender" /> -->

      <!--<appender-ref ref="FileAppender" /> -->

    </root>

  </log4net>