Nlog: jsonLayout encoding problem

Created on 27 Jul 2016  路  6Comments  路  Source: NLog/NLog

Hi I'm using jsonLoyout, but I'm having trouble encoding (utf-8). I can't show turkish character.

can you help me ?

Type :

  • Question

NLog version: (4.3.4)

Platform: ..Net 4.5

Current NLog config (xml)

    <target xsi:type="File"
                name="GateloggerTarget"
                fileName="C:\Logs\Payflex.Collection\GateLogger\${date:format=yyyy}\${date:format=MM}\${shortdate}.txt"
                encoding="utf-8"
                layout="${longdate}|${message}">
      <layout xsi:type="JsonLayout">
                <attribute name="Direction" layout="${event-context:item=Direction}" />
                <attribute name="TrackId" layout="${event-context:item=TrackId}" />
                <attribute name="MethodName" layout="${event-context:item=MethodName}" />
                <attribute name="HostAddress" layout="${event-context:item=HostAddress}" />
                <attribute name="Date" layout="${date:format=MM/dd/yyyy HH\:mm\:ss.fff}" />
                <attribute name="Message" layout="${message}" />
            </layout>
    </target>

Log output :
Message=\"*## 2304 \u0130\u015flem y\u00fcr\u00fct\u00fcl\u00fcyor.*"

json / json-layout question

Most helpful comment

As @304NotModified said, problem is in JsonEncodeLayoutRendererWrapper. But it is not a bug, just a config issue.

You need to disable JSON encoding for log messages. Set encode to false of the message attribute.

<attribute name="Message" layout="${message}" encode="false" />

See https://github.com/NLog/NLog/wiki/JsonLayout

P.S. Do not remove encoding="utf-8". You need it for file encoding.

I am closing this issue. If solution does not work for you, please let us know.

All 6 comments

@UgurAldanmaz could you help with this case?

if I do not use jsonLayout there is no problem. but JsonLayout it doesn't work. sample Nlog config. Like above

Sorry for late reply. I am investigating the reason.

As @304NotModified said, problem is in JsonEncodeLayoutRendererWrapper. But it is not a bug, just a config issue.

You need to disable JSON encoding for log messages. Set encode to false of the message attribute.

<attribute name="Message" layout="${message}" encode="false" />

See https://github.com/NLog/NLog/wiki/JsonLayout

P.S. Do not remove encoding="utf-8". You need it for file encoding.

I am closing this issue. If solution does not work for you, please let us know.

Thanks @UgurAldanmaz !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carkov1990 picture carkov1990  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments

sszost picture sszost  路  3Comments

BobSeu picture BobSeu  路  3Comments

imanushin picture imanushin  路  3Comments