问题
I use log4net for logging my logs. and use configuration here (only log the message):
<logger name="LogTracking">
<level value="INFO" />
<appender-ref ref="LogTrackingAppender" />
</logger>
<appender name="LogTrackingAppender" type="log4net.Appender.RollingFileAppender">
<file value="logging\urltracking\" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="20MB" />
<encoding value="utf-8" />
<datePattern value="yyyy'\\'MM'\\'dd'\\'yyyyMMddHH'.log'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>
But when i open my logs file, if in UTF-8 encoding the lines message seems normal. And if in ANSI encoding, these lines message have a unknown character at the beginning of the lines. See here:
<?xml version="1.0" encoding="utf-8"?><UrlTrackingObj><Url>mysite</Url><Action>view</Action><Ip>::1</Ip><Os>Windows 8.1</Os><Browser>Chrome 59.0</Browser></UrlTrackingObj>
Then when my app reads log lines, it can read and process this character. What is my configuration wrong? or any solution this solve this problem? I want my log line only:
<?xml version="1.0" encoding="utf-8"?><UrlTrackingObj><Url>mysite</Url><Action>view</Action><Ip>::1</Ip><Os>Windows 8.1</Os><Browser>Chrome 59.0</Browser></UrlTrackingObj>
回答1:
Those characters 
are the byte order mark (BOM):
The UTF-8 representation of the BOM is the (hexadecimal) byte sequence 0xEF,0xBB,0xBF. A text editor or web browser misinterpreting the text as ISO-8859-1 or CP1252 will display the characters  for this.
You can use the other encoding class rather than the default one to suppress the BOM
such as:
<encoding type="System.Text.UTF8Encoding"/>
System.Text.UTF8Encoding
来源:https://stackoverflow.com/questions/44838062/why-log4net-log-message-have-some-unknown-character