Search code examples
c#log4netadonetappender

How to log Byte[] data in log4net using AdoNetAppender


I want to log a gzip-compressed string, which will be in binary Byte[] format, in a [varbinary](max) SQL table column using log4net's AdoNetAppender.

My questions:

1) Is this possible? If so, what dbType I need to use as parameter in my config file below:

   <parameter>
    <parameterName value="@Data" />
    <dbType value="String" />
    <size value="2147483647" />
    <layout type="log4net.Layout.RawPropertyLayout">
      <key value="Data" />
    </layout>
  </parameter

2) Are there alternatives other than converting the value to a string and then logging it.


Solution

  • I think the best way to log you binary Byte[] is to convert it to a base64 string. There is no way to pass a Byte[] type as value to log4net logging methods.