Encoding problem with logging application block

Topics: Logging Application Block
Oct 3, 2007 at 6:11 AM
Hi,
Although I can successfully write log info via Logger.Write(...) into a file (with Flat FileTrace Listener).

However, since there are some Big5(Traditional Chinese) characters in the logged message, so that the logging file contains some unrecognized tokens such as ?冽蝡臭葉?瑚?撌脣??隞嗥??????.

How can I specify the encoding of Flat FileTrace Listener?

Regards,
Ricky.


Oct 3, 2007 at 11:56 AM
Hi,

The Flat File Trace Listener inherits its behavior from System.Diagnostics' TextWriterTraceListener, so it uses a fixed UTF8 listener that does not emit the UTF8 identifier when used from configuration (I got this from reflector, couldn't find documentation for this). You cannot change this encoding.

Fernando
Oct 4, 2007 at 12:32 AM

Thanks,

Is there a workaround to transform BIG5 characters to UTF8 ones?

Ricky.


fsimonazzi wrote:
Hi,

The Flat File Trace Listener inherits its behavior from System.Diagnostics' TextWriterTraceListener, so it uses a fixed UTF8 listener that does not emit the UTF8 identifier when used from configuration (I got this from reflector, couldn't find documentation for this). You cannot change this encoding.

Fernando

Oct 4, 2007 at 7:07 AM
Actually I don't think Fernando is quite correct here. The TextWriterTraceListener (and by extension, the FlatFileTraceListener) can actually support any encoding, provided you create it using a constructor that takes a StreamWriter, and provided you created the StreamWriter with a constuctor that lets you specify the encoding.

However if you are wiring up the logging block using configuration (as 99% of people do), you don't get any choice over which constructor is used, as the FlatFileTraceListenerAssembler class (in the Logging\Configuration\FlatFileTraceListenerData.cs file) is hard-wired to use a different constructor.

If you are happy to hard-code a different encoding, you could probably just modify the assembler class to do this. If you wanted a more solid solution you would probably want to modify or derive from the FFTL and expose an Encoding property in the configuration file.

HTH
Tom
Oct 4, 2007 at 12:59 PM
Sounds like it could be recommended as a new feature request for the next release? For internationals specifying the format seems like a sensible option.
Jun 29, 2010 at 9:36 AM

Does anybody know was it solved in EntLib 5?

Jul 1, 2010 at 2:19 AM

This is not supported in EntLib 5.  The way to do this would still be to create a custom trace listener.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com