Bill Blankenship Bill Blankenship - 19 days ago 5
C# Question

Log4net logging to Oracle throwing error when logging to Number fields?

I have been battling this issue for quite some time. When I try to log to a Number(38,0) field in an Oracle 11g database. I get this error:


log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Exception
while writing to database System.FormatException: Input string was not
in a correct format. at System.Number.StringToNumber(String str,
NumberStyles options, NumberBuffer& number, NumberFormatInfo info,
Boolean parseDecimal)


<parameter>
<parameterName value=":my_param" />
<dbType value="Int32" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{my_param}" />
</layout>
</parameter>


I have tried setting the size of the Int32. I have tried decimal and also decimal with setting the scale and precision. I am unsure what else to do but I know the value present is numeric.

Here is some code calling the logger to log and also where the value is being defaulted.

log4net.LogicalThreadContext.Properties[":my_param"] = 132;
log.Info("Application Start"); //Error occurs here in the output window

Answer

You want to remove that colon when you're adding the my_param property to the LogicalThreadContext.

i.e.

log4net.LogicalThreadContext.Properties["my_param"] = 132;

Currently your use of the %property syntax is mismatched with the name of the property you're adding.

Comments