tags:

views:

122

answers:

3

Hi,

I have a byte[] with some data in it, I would like to write this byte array AS-IS to the log file using log4.net. The problems that i am facing is that

There are no overload for byte[] in TextWriter, so even implementing an IObjectRenderer is of no use. I dont have access to the underlying Stream object of Log4.net Also tried converting byte[] into char[] still when i write it, it adds an extra byte.

Is this even possible with Log4.net.

Thanx in Advance.

+2  A: 

Log files are usually plain text files. It's probably best to log your byte array represented as string.

Have a look at BitConverter.ToString or Convert.ToBase64String.

dtb
the only problem with this approach is that the log file would be double the size and also not very readable as the data contains a mix of human readable string and binary info.
like.no.other
Then don't write it to the log file :-) Log files are for diagnostic messages, not piles of binary data.
dtb
+3  A: 

Nope. Have you thought about writing it out as a hex string (see this post)?

Tom Cabanski
the only problem with this approach is that the log file would be double the size and also not very readable as the data contains a mix of human readable string and binary info.
like.no.other
If you know how to write out HEX string, you can feel free to write out other string patterns if you like.
Lex Li
A: 

I also think that logging any larger data is kind of useless, however, i guess this is what you are looking for - this converts your bytes to string.

 System.Text.Encoding.ASCII.GetString(byteArray)

I believe you can figure out how to use that for logging.

Pz, the TaskConnect developer

Pz