Hi!
Type : Bug
NLog version: 4.5.11
Platform: .Net 4.5
I got the error below on my internal log and keeps writing same log continuously. And after geting this error it stopped writing logs.
internal.log:
2020-12-22 21:12:00.3284 Error Error has been raised. Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at NLog.Internal.AppendBuilderCreator..ctor(StringBuilder appendTarget, Boolean mustBeEmpty)
at NLog.Layouts.Layout.RenderAppendBuilder(LogEventInfo logEvent, StringBuilder target, Boolean cacheLayoutResult)
at NLog.Targets.FileTarget.RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target)
at NLog.Targets.FileTarget.RenderFormattedMessageToStream(LogEventInfo logEvent, StringBuilder formatBuilder, Char[] transformBuffer, MemoryStream streamTarget)
at NLog.Targets.FileTarget.Write(LogEventInfo logEvent)
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
Current NLog 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" throwExceptions="false" autoReload="true" internalLogLevel="Warn">-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--<extensions>
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>-->
<targets async="true">
<!--<target xsi:type="ElasticSearch"
name="elastic"
uri="http://localhost:aaa/"
index="aaa-log-${date:format=yyyy.MM.dd}"
includeAllProperties='true'>
<field name='messageTemplate' layout='${message:raw=true}' />
</target>-->
<target xsi:type="File" name="f" fileName="./aaa-logs/${date:format=yyyy-MM}/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<!--<logger name="*" minlevel="Trace" writeTo="elastic" />-->
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!
Hi,
NLog 4.5.11 is more than 2 years old. Please update to a newer version.
Feel free to open a new issue after upgrade, but we need at least a reproduction case.
Our time is limited, unfortunately we cannot support these old versions anymore.
That NullReferenceException-callstack looks like the side-effect of an out-of-memory-error, where a previous attempt to clear the StringBuilder has failed (StringBuilder clear actually re-allocates a whole new char-buffer-array).
When StringBuilder-clear fails, then it is not able to reuse the StringBuilder, and so the reusable-StringBuilder is no longer available. Guess NLog could be improved to better handle an out-of-memory-condition (internal state should not be corrupted).
Created #4222 to improve internal-state-recovery after a low-memory-situation.
https://www.nuget.org/packages/NLog/4.7.7 has been released
Most helpful comment
https://www.nuget.org/packages/NLog/4.7.7 has been released