Hi I'm using jsonLoyout, but I'm having trouble encoding (utf-8). I can't show turkish character.
can you help me ?
Type :
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.*"
@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
Ah then the bug is probable in https://github.com/NLog/NLog/blob/master/src/NLog/LayoutRenderers/Wrappers/JsonEncodeLayoutRendererWrapper.cs
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 !
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
encodetofalseof 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.