I am facing a trouble with an AdoNetAppender. Things work fine for messages upto 2000 chars length. Everything falls apart if the message(PI_S_MESSAGE) is > 2000 chars. My database is Oracle 10g and shown below is the appender config. Connect string is injected on the fly, when initializing the 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>
<l开发者_如何转开发evel value="All"/>
<appender-ref ref="MyAppender"/>
</root>
When debug mode is enabled, it pumps out an oracle error
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)
Can someone please help?
Fixed by changing the dbType
attribute for the PI_S_MESSAGE
parameter to AnsiString
.
Perhaps it was trying an nvarchar
binding when used with a dbType as String
.
Eventhough unrelated, this thread saved my arse. https://forum.hibernate.org/viewtopic.php?p=2369841
New config follow.
<?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>
精彩评论