Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 605
nakhli Avatar asked Aug 05 '11 08:08

nakhli


People also ask

Is log4net structured logging?

log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.

What is log4net and log4j?

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the excellent Apache log4j™ framework to the Microsoft® . NET runtime. We have kept the framework similar in spirit to the original log4j while taking advantage of new features in the .

Where are log4net logs stored?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation. The different log files are described in Services logs.


1 Answers

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.

like image 162
nakhli Avatar answered Sep 29 '22 09:09

nakhli