简体   繁体   English

如何使用AdoNetAppender在Log4net中记录Byte []数据

[英]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 . 我想使用log4net的AdoNetAppender[varbinary](max) SQL表列中记录gzip压缩的字符串,该字符串将采用二进制Byte[]格式。

My questions: 我的问题:

1) Is this possible? 1)这可能吗? If so, what dbType I need to use as parameter in my config file below: 如果是这样,我需要在下面的配置文件中使用什么dbType作为参数:

   <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. 2)除了将值转换为字符串然后进行记录之外,还有其他选择吗?

I think the best way to log you binary Byte[] is to convert it to a base64 string. 我认为记录二进制Byte []的最佳方法是将其转换为base64字符串。 There is no way to pass a Byte[] type as value to log4net logging methods. 无法将Byte []类型作为值传递给log4net日志记录方法。

You can convert your string to Byte[] in your CommandText like this: 您可以像这样在CommandText中将字符串转换为Byte []:

<commandText value="INSERT INTO [LogServer]
    ([Date], [Logger], [message], [Exception], [BinaryMessage], [BinaryException]) 
    VALUES
    (@log_date, @logger, @message, @exception, cast(@message as varbinary(max)), cast(@exception as varbinary(max)) )"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM