Log4Net: Logging in 2 byte languages (japanese, chinese etc.)

nakhli picture nakhli · Aug 5, 2011 · Viewed 15.4k times · Source

I would like to log data to a file in 2 byte languages (chinese, japanese etc) using log4net.

How to properly configure log4net to do that?

Answer

nakhli picture nakhli · Nov 4, 2011

The log file encoding is specified by FileAppender.Encoding. It can be configured using the encoding configuration element. Example:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="file.log" />
    <encoding value="utf-8" />
    ...

The value is the code page name. The corresponding Encoding is obtained using the System.Text.Encoding.GetEncoding(string) method. For a list of code pages, see the Encoding class documentation.