log4net AdoNetAppender 缺少默认参数
log4net AdoNetAppender missing default parameter
尝试将 log4net AdoNetAppender 与 example/default 配置一起使用我收到一个奇怪的参数错误
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Exception while writing to database
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@log_date' is not contained by this SqlParameterCollection.
我没有发现参数声明有任何问题
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
但是,尝试删除参数只是下一个以相同方式失败的参数,我尝试更改连接字符串,认为可能存在我没有看到的潜在错误,不是运气要么。
log4net 调试日志甚至清楚地表明
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
对于每个参数,所以我真的不知道发生了什么
下面是我为 log4net 准备的完整配置
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="DBAppender" />
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="DebugAppender" />
</root>
<appender name="DBAppender" type="log4net.Appender.AdoNetAppender">
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<connectionStringName value="CustomerDB" />
<bufferSize value="1" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<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>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
<immediateFlush value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
</log4net>
您需要更新到 log4net 2.0.5、2.0.4 AdoNetAppender 已损坏。
尝试将 log4net AdoNetAppender 与 example/default 配置一起使用我收到一个奇怪的参数错误
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Exception while writing to database
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@log_date' is not contained by this SqlParameterCollection.
我没有发现参数声明有任何问题
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
但是,尝试删除参数只是下一个以相同方式失败的参数,我尝试更改连接字符串,认为可能存在我没有看到的潜在错误,不是运气要么。
log4net 调试日志甚至清楚地表明
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
对于每个参数,所以我真的不知道发生了什么
下面是我为 log4net 准备的完整配置
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="DBAppender" />
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="DebugAppender" />
</root>
<appender name="DBAppender" type="log4net.Appender.AdoNetAppender">
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<connectionStringName value="CustomerDB" />
<bufferSize value="1" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<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>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
<immediateFlush value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
</log4net>
您需要更新到 log4net 2.0.5、2.0.4 AdoNetAppender 已损坏。