I have a .net core application that runs successfully in production. I use Nlog to write to the log, it writes to debug.txt and graylog. It works successfully on k8s. However, when I try to debug locally on Windows 10, if graylog is enabled, the application crashes with the following error. If graylog is disabled, then everything is fine. here is part of nlog.config
<target xsi:type="Gelf" name="graylog" endpoint="udp://graylogHost" facility="netcore"
SendLastFormatParameter="true" gelfVersion="1.1">
<parameter name="assembly" layout="${appdomain:format={1\}:cached=True}" />
<parameter name="log-level" layout="${level:uppercase=true}" />
<parameter name="callsite"
layout="${callsite:className=True:fileName=False:includeSourcePath=False:methodName=True}" />
<parameter name="threadid" layout="${threadid}" />
<!--<parameter name="hostname" layout="${right:inner=${hostname}:length=5}"/>-->
<parameter name="hostname" layout="${hostname}" />
<parameter name="activityId"
layout="${activityid:whenEmpty=${aspnet-TraceIdentifier:whenEmpty=${activity:property=TraceId}}}" />
<parameter name="hierarchicalId"
layout="${activity:property=Id}" />
<parameter name="spanId"
layout="${activity:property=SpanId}" />
<parameter name="parentId"
layout="${activity:property=ParentId}" />
<parameter name="traceId"
layout="${activity:property=TraceId}" />
</target>
And here is error
type hereStack overflow.
Repeat 12112 times:
--------------------------------
at System.Reflection.Emit.InternalAssemblyBuilder.Equals(System.Object)
at System.Reflection.Emit.InternalModuleBuilder.Equals(System.Object)
--------------------------------
at System.Collections.Generic.ObjectEqualityComparer`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].IndexOf(System.__Canon[], System.__Canon, Int32, Int32)
at System.Array.IndexOf[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon[], System.__Canon, Int32, Int32)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContract ByRef, System.Object ByRef)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, System.Object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(Newtonsoft.Json.JsonWriter, System.Object, System.Type)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(Newtonsoft.Json.JsonWriter, System.Object, System.Type)
at Newtonsoft.Json.Linq.JToken.FromObjectInternal(System.Object, Newtonsoft.Json.JsonSerializer)
at NLog.Web.AspNetCore.Targets.Gelf.GelfConverter.AddAdditionalField(System.Collections.Generic.IDictionary`2<System.String,Newtonsoft.Json.Linq.JToken>, System.Collections.Generic.KeyValuePair`2<System.Object,System.Object>)
at NLog.Web.AspNetCore.Targets.Gelf.GelfConverter.GetGelfJson(NLog.LogEventInfo, System.String, System.String)
at NLog.Web.AspNetCore.Targets.Gelf.GelfTarget.Write(NLog.LogEventInfo)
at NLog.Targets.Target.Write(NLog.Common.AsyncLogEventInfo)
at NLog.Targets.Target.Write(System.Collections.Generic.IList`1<NLog.Common.AsyncLogEventInfo>)
at NLog.Targets.Target.WriteAsyncThreadSafe(System.Collections.Generic.IList`1<NLog.Common.AsyncLogEventInfo>)
at NLog.Targets.Target.WriteAsyncLogEvents(System.Collections.Generic.IList`1<NLog.Common.AsyncLogEventInfo>)
at NLog.Targets.Wrappers.AsyncTargetWrapper.WriteLogEventsToTarget(System.Collections.Generic.IList`1<NLog.Common.AsyncLogEventInfo>, System.String)
at NLog.Targets.Wrappers.AsyncTargetWrapper.WriteLogEventsInQueue(Int32, System.String)
at NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(System.Object)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.TimerQueueTimer.Fire(Boolean)
at System.Threading.TimerQueueTimer.System.Threading.IThreadPoolWorkItem.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
I updated Nlog, I updated Gelf. I removed Newtonsoft from app, but nothing helped. I will be glad to any ideas: why this code work on K8s and not work on Win10
You can try and upgrade to the latest Newtonsoft.Json-nuget-package (Adding it as explicit dependency for your application-project). Maybe they have changed the default JSON-serializer-settings to prevent StackOverflow.
Alternative you can stop using NLog.Web.AspNetCore.Targets.Gelf, and instead use NLog NetworkTarget together with NLog.GelfLayout (Though it doesn't support
SendLastFormatParameter="true"
).