Bill Blankenship Bill Blankenship - 2 months ago 13
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)

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

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


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


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

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