使用 NLog 记录波斯语消息
Logging Persian messages with NLog
在我的 ASP.NET MVC 项目中,我在 Web.config 中有如下配置:
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="default" xsi:type="File" fileName="logs/app-log.txt" layout="
--------------------- ${level} (${longdate}) ----------------------$
IP: ${aspnet-request-ip}
Call Site: ${callsite}
${level} message: ${message}"/> archiveFileName="logs/archives/app-log.{#}.txt" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" />
</targets>
<rules>
<logger name="*" writeTo="default" />
</rules>
</nlog>
如果我的日志消息是波斯语文本,那么在日志文件中我将问号标记为 ?????
而不是波斯语文本。
我该如何解决这个问题?任何帮助将不胜感激!
正如@ramesh 指出的那样,使用 Encoding="utf-16"
并尝试 writeBom="true"
。
此文件目标的 nlog 文档是 https://github.com/NLog/NLog/wiki/File-target,它可能会给您更多帮助。
我在目标元素中添加了 encoding="UTF8"
属性
在我的 ASP.NET MVC 项目中,我在 Web.config 中有如下配置:
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="default" xsi:type="File" fileName="logs/app-log.txt" layout="
--------------------- ${level} (${longdate}) ----------------------$
IP: ${aspnet-request-ip}
Call Site: ${callsite}
${level} message: ${message}"/> archiveFileName="logs/archives/app-log.{#}.txt" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" />
</targets>
<rules>
<logger name="*" writeTo="default" />
</rules>
</nlog>
如果我的日志消息是波斯语文本,那么在日志文件中我将问号标记为 ?????
而不是波斯语文本。
我该如何解决这个问题?任何帮助将不胜感激!
正如@ramesh 指出的那样,使用 Encoding="utf-16"
并尝试 writeBom="true"
。
此文件目标的 nlog 文档是 https://github.com/NLog/NLog/wiki/File-target,它可能会给您更多帮助。
我在目标元素中添加了 encoding="UTF8"
属性