NLog 没有正确写入变音符号字符
NLog doesn't writes diacritics chars properly
我正在尝试使用 nlog 将消息记录到文件中。我的问题是,每当我尝试将波兰语字符用作“ąćęśł”时,它们在日志文件中显示为 ¹æê³。其他国家/地区的特殊字符确实有效(如 ä ö 等)。可能是什么问题?
这就是我 nlog.config 的开头:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info">
<targets>
<target
xsi:type="File"
name="allInfo"
fileName="${whenEmpty:whenEmpty=${basedir}:inner=${configsetting:item=PathToFiles}}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}"
archiveEvery="Month"
archiveFileName="${whenEmpty:whenEmpty=${basedir}:inner=${configsetting:item=PathToFiles}}/logs/archive/log-${shortdate}.log"
maxArchiveFiles="50"/>
</targets>
<rules>
<logger
name="*"
minlevel="Trace"
writeTo="allInfo"/>
</rules>
</nlog>
</configuration>
如您所见,utf-8 就在那里。不知道如何解决它。
添加encoding="utf-8"
to the file target.
encoding - File encoding name like "utf-8", "ascii" or "utf-16". See Encoding class on MSDN. Defaults to Encoding.Default.
<target
xsi:type="File"
name="allInfo"
...
encoding="utf-8"
/>
我正在尝试使用 nlog 将消息记录到文件中。我的问题是,每当我尝试将波兰语字符用作“ąćęśł”时,它们在日志文件中显示为 ¹æê³。其他国家/地区的特殊字符确实有效(如 ä ö 等)。可能是什么问题? 这就是我 nlog.config 的开头:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info">
<targets>
<target
xsi:type="File"
name="allInfo"
fileName="${whenEmpty:whenEmpty=${basedir}:inner=${configsetting:item=PathToFiles}}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}"
archiveEvery="Month"
archiveFileName="${whenEmpty:whenEmpty=${basedir}:inner=${configsetting:item=PathToFiles}}/logs/archive/log-${shortdate}.log"
maxArchiveFiles="50"/>
</targets>
<rules>
<logger
name="*"
minlevel="Trace"
writeTo="allInfo"/>
</rules>
</nlog>
</configuration>
如您所见,utf-8 就在那里。不知道如何解决它。
添加encoding="utf-8"
to the file target.
encoding - File encoding name like "utf-8", "ascii" or "utf-16". See Encoding class on MSDN. Defaults to Encoding.Default.
<target
xsi:type="File"
name="allInfo"
...
encoding="utf-8"
/>