zoukankan      html  css  js  c++  java
  • log4Net日志插入到ORACLE

    在配置文件中增加如下:

        <!--记录到oracle数据库方式-->
        <appender name="AdoNetAppender_Oracle" type="log4net.Appender.AdoNetAppender">
          <connectionType value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <connectionString value="data source=myname3;User ID=newhcms2;Password=newhcms2" />
          <commandText value="INSERT INTO NEWHCMS2.SYS_OPERATORLOG (KEYID, USER_ID, USER_NAME, CURRENT_DATE, SYS_NAME, OPERATOR_TYPE, OPERATOR_PAGE, COMPUTER_IP, COMPUTER_NAME, NOTE) VALUES (SEQ_SYS_OPERATORLOG.NEXTVAL, :operator, :log_level, :log_level, :log_date, :browser, :logger, :thread, :ip, :message, :error)" />

          <bufferSize value="1" />

        <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=":operator" />
            <dbType value="Int16" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%property{Operator}" />
            </layout>
          </parameter>

       <!--IP-->
          <parameter>
            <parameterName value=":ip" />
            <dbType value="String" />
            <size value="20" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%property{IP}" />
            </layout>
          </parameter>

         <!--浏览器-->
          <parameter>
            <parameterName value=":browser" />
            <dbType value="String" />
            <size value="50" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%property{Browser}" />
            </layout>
          </parameter>

          <!--消息-->
          <parameter>
            <parameterName value=":message" />
            <dbType value="String" />
            <size value="3000" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%property{Message}" />
            </layout>
          </parameter>

       <!--错误-->
          <parameter>
            <parameterName value=":error" />
            <dbType value="String" />
            <size value="3000" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%property{Error}" />
            </layout>
          </parameter>

      <!--消息--><!--
          <parameter>
            <parameterName value=":state" />
            <dbType value="String" />
            <size value="3000" />
            <layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
              <conversionPattern value="%message" />
            </layout>
          </parameter>-->
        </appender>

    特别需要注意到是:commandText value 中的SQL语句,如果库中有多个表空间,必须在语句中把表空间加上,如:

    ="INSERT INTO NEWHCMS2.SYS_OPERATORLOG (KEYID, USER_ID, USER_NAME, CURRENT_DATE, SYS_NAME, OPERATOR_TYPE, OPERATOR_PAGE, COMPUTER_IP, COMPUTER_NAME, NOTE) VALUES (SEQ_SYS_OPERATORLOG.NEXTVAL, :operator, :log_level, :log_level, :log_date, :browser, :logger, :thread, :ip, :message, :error)"

    NEWHCMS2就是表空间名;

    还有就是声明了的参数,都必须在SQL语句中使用;

     :operator, :log_level, :log_level, :log_date, :browser, :logger, :thread, :ip, :message, :error

    在配置中声明了 它们,就 必须在SQL中使用,也就是说SQL语句中的参数与声明中必须一一对应,声明中不能用多余的参数声明;如::state这个参数在SQL语句中没有用到,也不能在声明中出现,必须把它屏蔽!

  • 相关阅读:
    算法导论————KMP
    KMP算法
    几个很好的OJ网站
    查找(二分、hash、桶)
    动态规划
    贪心(未完待续)
    搜索的题
    codeVS 1031 质数环
    《将博客搬至CSDN》
    HDU1717小数化分数2
  • 原文地址:https://www.cnblogs.com/qipilang/p/1629496.html
Copyright © 2011-2022 走看看