我在使用AdoNetAppender时遇到了麻烦。对于长达2000个字符的消息,事情很好。如果消息(PI_S_MESSAGE)是>则一切都会崩溃。 2000个字符。我的数据库是Oracle 10g,下面显示的是appender配置。初始化appender时,动态注入连接字符串。
<?xml version="1.0" encoding="utf-8" ?><log4net>
<appender name="MyAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="0" />
<connectionType value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<commandText value="INSERT INTO LOG_TABLE(Datetime,Log_Level,userid,Message,machine) VALUES (:PI_D_DATE, :PI_S_LEVEL, :PI_S_USERID, :PI_S_MESSAGE, :PI_S_MACHINE)" />
<parameter>
<parameterName value=":PI_D_DATE" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{dd-MMM-yyyy HH:mm:ss}" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_LEVEL" />
<dbType value="String" />
<size value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_USERID" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%u" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_MESSAGE" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_MACHINE" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{log4net:HostName}" />
</layout>
</parameter>
</appender>
<root>
<level value="All"/>
<appender-ref ref="MyAppender"/>
</root>
启用调试模式后,它会发出oracle错误
log4net:ERROR [AdoNetAppender] Exception while writing to database
System.Data.OracleClient.OracleException: ORA-01461: can bind a LONG value only for insert into a LONG column
at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)
有人可以帮忙吗?
答案 0 :(得分:0)
通过将dbType
参数的PI_S_MESSAGE
属性更改为AnsiString
来解决此问题。
也许它在与dbType一起用作nvarchar
时尝试String
绑定。
虽然无关,但这个帖子救了我的屁股。 https://forum.hibernate.org/viewtopic.php?p=2369841
新配置。
<?xml version="1.0" encoding="utf-8" ?><log4net>
<appender name="MyAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="0" />
<connectionType value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<commandText value="INSERT INTO LOG_TABLE(Datetime,Log_Level,userid,Message,machine) VALUES (:PI_D_DATE, :PI_S_LEVEL, :PI_S_USERID, :PI_S_MESSAGE, :PI_S_MACHINE)" />
<parameter>
<parameterName value=":PI_D_DATE" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{dd-MMM-yyyy HH:mm:ss}" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_LEVEL" />
<dbType value="String" />
<size value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_USERID" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%u" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_MESSAGE" />
<dbType value="AnsiString" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value=":PI_S_MACHINE" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{log4net:HostName}" />
</layout>
</parameter>
</appender>
<root>
<level value="All"/>
<appender-ref ref="MyAppender"/>
</root>