使用NLog记录波斯消息

问题描述 投票:0回答:2

在我的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>

如果我的日志消息是波斯文字,则在日志文件中,我有问号????????。而不是波斯文字。我该如何解决这个问题?任何帮助都将被申请!

c# asp.net-mvc nlog
2个回答
0
投票

正如@ramesh指出使用Encoding =“ utf-16”的tru并尝试使用writeBom =“ true”。

此文件目标的nlog文档为https://github.com/NLog/NLog/wiki/File-target,可能会为您提供更多帮助。


0
投票

我在目标元素中添加了encoding =“ UTF8”属性

© www.soinside.com 2019 - 2024. All rights reserved.