Gelf 使用时,net core 应用程序在 Windows 上崩溃

问题描述 投票:0回答:1

我有一个在生产中成功运行的 .net core 应用程序。 我使用Nlog写入日志,它写入debug.txt和graylog。 在k8s上运行成功。 但是,当我尝试在 Windows 10 上本地调试时,如果启用 Graylog,应用程序会崩溃并出现以下错误。 如果graylog被禁用,那么一切都很好。 这是 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>

这是错误

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()

我更新了Nlog,我更新了Gelf。我从应用程序中删除了 Newtonsoft,但没有任何帮助。 我很高兴有任何想法:为什么这个代码在 K8s 上工作而在 Win10 上不起作用

.net-core nlog gelf
1个回答
0
投票

您可以尝试升级到最新的 Newtonsoft.Json-nuget-package (将其添加为应用程序项目的显式依赖项)。也许他们更改了默认的 JSON 序列化器设置以防止 StackOverflow。

您也可以停止使用 NLog.Web.AspNetCore.Targets.Gelf,而是将 NLog.GelfLayout 与 NLog NetworkTarget 一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.