Log4Net 不使用 commandType 调用存储过程

Log4Net not calling the stored procedure using commandType

长话短说,我正在使用 Log4net,我想在内部写入调用存储过程的数据库。这是 web.config 中的设置:

<log4net debug="true">
<root>
  <level value="ALL" />
  <appender-ref ref="AdoNetAppender" />
  <appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="1" />
  <threshold value="ALL"/>
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <connectionString value="data source=***;initial catalog=***;user id=**;password=***;MultipleActiveResultSets=True;" />
  <commandText value="iE_AddUserActivityLog" />
  <commandType value="StoredProcedure" />
  <parameter>
    <parameterName value="@log_date" />
    <dbType value="DateTime" />
    <layout type="log4net.Layout.RawTimeStampLayout" />
  </parameter>
  <parameter>
    <parameterName value="@thread" />
    <dbType value="AnsiString" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%thread" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@log_level" />
    <dbType value="AnsiString" />
    <size value="50" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@logger" />
    <dbType value="AnsiString" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%logger" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@page" />
    <dbType value="AnsiString" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{page}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@host" />
    <dbType value="AnsiString" />
    <size value="50" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{host}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@ipaddress" />
    <dbType value="AnsiString" />
    <size value="15" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{ipaddress}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@browser" />
    <dbType value="AnsiString" />
    <size value="15" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{browser}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@platform" />
    <dbType value="AnsiString" />
    <size value="15" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{platform}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@device" />
    <dbType value="AnsiString" />
    <size value="15" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%property{device}" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@message" />
    <dbType value="AnsiString" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@exception" />
    <dbType value="AnsiString" />
    <size value="2000" />
    <layout type="log4net.Layout.ExceptionLayout" />
  </parameter>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="logs\log.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="10MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
  </layout>
</appender>
</log4net>

有人可以帮我理解为什么我不能使用 commandType 吗?因为如果我使用:

<commandText value="INSERT INTO user_activity_log ([Date],[Thread],[Level],[Logger],[page],[host],[browser],[platform],[device],[ipaddress],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @page, @host, @browser, @platform, @device, @ipaddress, @message, @exception)" />

或:

<commandText value="exec iE_AddUserActivityLog @log_date, @thread, @log_level, @logger, @page, @host, @browser, @platform, @device, @ipaddress, @message, @exception" />

我看得出来是在写

更新:我也尝试以这种方式引入 DBO 前缀:

  <commandText value="dbo.iE_AddUserActivityLog" />
  <commandType value="StoredProcedure" />

好的,我能够解决它。但我不确定为什么。基本上,我需要重命名 web.config 中的一些参数,以便与存储过程中的相同名称相匹配。