Nlog: Cyrillic text incorrect writing

Created on 5 Oct 2016  路  4Comments  路  Source: NLog/NLog

Feature request for NLog version: 4.3.9

My config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  autoReload="true">
  <variable name="logDirectory" value="${basedir}/App_Data/Logs" />
  <targets encoding="UTF-8" enableFileDelete="true" createDirs="true">
    <target name="file" xsi:type="File" fileName="${logDirectory}/${shortdate}.log"
      layout="#${date:format=HH\:mm\:ss}|${level}|${exception:format=Message}|${exception:format=StackTrace}" />
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="file" />
  </rules>
</nlog>

And I got ???? when I have in message Cyrillic text

I have wrote text code

using (StreamWriter sw = new StreamWriter(this.Server.MapPath("~/App_Data/logs/test.log"),true))
{
      sw.WriteLine(exc.Message);
}

And Cyrillic text write is fine

question

Most helpful comment

Noticed the problem:

  <targets encoding="UTF-8" enableFileDelete="true" createDirs="true">
    <target name="file" xsi:type="File" fileName="${logDirectory}/${shortdate}.log"
      layout="#${date:format=HH\:mm\:ss}|${level}|${exception:format=Message}|${exception:format=StackTrace}" />
  </targets>

should be

``````
xsi:type="File" fileName="${logDirectory}/${shortdate}.log" encoding="UTF-8" enableFileDelete="true" createDirs="true"

``` layout="#${date:format=HH\:mm\:ss}|${level}|${exception:format=Message}|${exception:format=StackTrace}" />

``````

All 4 comments

Could you post an example of Cyrillic text which goes wrong? (Also as image please, to be sure)

On text "袣芯薪褌褉芯谢谢械褉 写谢褟 锌褍褌懈 "/1" 薪械 薪邪泄写械薪 懈谢懈 薪械 褉械邪谢懈蟹褍械褌 懈薪褌械褉褎械泄褋 IController." I get "?????????? ??? ???? "/1" ?? ?????? ??? ?? ????????? ????????? IController."

Noticed the problem:

  <targets encoding="UTF-8" enableFileDelete="true" createDirs="true">
    <target name="file" xsi:type="File" fileName="${logDirectory}/${shortdate}.log"
      layout="#${date:format=HH\:mm\:ss}|${level}|${exception:format=Message}|${exception:format=StackTrace}" />
  </targets>

should be

``````
xsi:type="File" fileName="${logDirectory}/${shortdate}.log" encoding="UTF-8" enableFileDelete="true" createDirs="true"

``` layout="#${date:format=HH\:mm\:ss}|${level}|${exception:format=Message}|${exception:format=StackTrace}" />

``````

Thank you for help me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jerefeny picture Jerefeny  路  3Comments

npandrei picture npandrei  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments

imanushin picture imanushin  路  3Comments

JustArchi picture JustArchi  路  3Comments