0

I have adonetappender configured in my .net application for some parameters i have a fixed length in database for the column but in my logging data length get exceeded. From log4net trace log i find error as

log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Exception while writing to database
MySql.Data.MySqlClient.MySqlException: Data too long for column 'action' at row 1
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
   at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
log4net: Shutdown called on Hierarchy [log4net-default-repository]

parameter in my log4net config is as follows

  <parameter>
      <parameterName value="action" />
      <dbType value="String" />
      <size value="45" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5c{1}.%M" />
      </layout>
    </parameter>

Any idea i can handle the max length in config ?

Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93
  • You set the parameter's [size property](https://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderParameter.Size.html) as "The maximum size, in bytes, of the data within the column". – stuartd May 26 '15 at 13:42
  • How can i correct it? – Kamran Shahid May 26 '15 at 14:26
  • I think I might have explain wrong. In my database the size of the column is 45 length varchar so i have put exactly 45 length in my param. But in different places the classname + methodname get exceeded the length of 45. So i am getting this error. is there someway that log4net automatically handle the length without thrwoing this error – Kamran Shahid May 26 '15 at 19:30

1 Answers1

0

I would suggest to increase the column length, since you would loose your log.

If you want your log to be fixed size, then your setting should work. OR set it to "-1" or remove size property completely, that way it would now depend on length of your table column.

Also if you are using stored procedure, I realized that you are missing "@"

<parameter>
  <parameterName value="@action" />
  <dbType value="String" />
  <size value="-1" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%5c{1}.%M" />
  </layout>
</parameter>
Sanjay Sutar
  • 544
  • 1
  • 5
  • 18