Log2console is a visual log viewing tool. Chinese characters are garbled during use.
The solution is as follows.
I,Log4net cannot output Chinese logs
Cause: log4net. appender. udpappender of log4net must be used in combination with log2console to output logs and shield all non-Chinese characters. Log4net source code problem occurs in the util \ transform. CS file public static string maskxmlinvalidcharacters (string textdata, string mask)
This function is intended to replace the invalid characters in the output message "? ". Unfortunately, this regular expression is incorrect.
Private Static RegEx invalidchars = new RegEx (@ "[^ \ x09 \ x0a \ x0d \ x20-\ xFF \ u00ff-\ u07ff \ ue000-\ ufffd]", regexoptions. compiled );
This regular expression replaces a large part of the characters, including Chinese characters and Japanese and Korean characters.
Solution: I commented out the regular expression replacement sentence and re-compiled it.
Change return invalidchars. Replace (textdata, mask); to return textdata;
II,Log2console cannot display Chinese logs
1) Use log2console to monitor system file logs. cause:Log2consoleThe source code of is not specified when _ filereader is created
Solution: Modify the initialize method of the filereceiver. CS file and SET _ filereader = new streamreader (New filestream (_ filetowatch, filemode. Open, fileaccess. Read, fileshare. readwrite ));
Changed:
_ Filereader = new streamreader (New filestream (_ filetowatch, filemode. Open, fileaccess. Read, fileshare. readwrite), system. Text. encoding. Default );
Then re-compile.
2) use the UDP method of log2console to obtain the log cause:Log2consoleTo obtain UDP information, use UTF-8 to obtain the string.
Solution: Modify the START () method of the udpreceiver. CS file
String loggingevent = system. Text. encoding. utf8.getstring (buffer );
Changed:
String loggingevent = system. Text. encoding. Default. getstring (buffer );
Then re-compile.
Log2consoleSource code can be downloaded at the address below
Http://log2console.codeplex.com/
After compilationLog4net.rarAndLog2console