简体   繁体   English

使用 NLog 记录波斯语消息

[英]Logging Persian messages with NLog

In my ASP.NET MVC project I have below config in Web.config as below:在我的 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>

If my log message is in Persian text then in log file I have question mark as ?????如果我的日志消息是波斯语文本,那么在日志文件中我的问号为????? instead of the Persian text.而不是波斯文。

How can I fix this problem?我该如何解决这个问题? Any help will be appreciated!任何帮助将不胜感激!

I added encoding="UTF8" attribute in target element我在目标元素中添加了encoding="UTF8"属性

As @ramesh pointed out tru using Encoding="utf-16" and also try writeBom="true" .正如@ramesh 指出 tru 使用Encoding="utf-16"并尝试writeBom="true"

The nlog documentation of this file target is https://github.com/NLog/NLog/wiki/File-target and it might give you some more help.此文件目标的 nlog 文档是https://github.com/NLog/NLog/wiki/File-target ,它可能会给您更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM