nLog 4.4.11中添加多个异步文件目标时的线程死锁问题

时间:2018-05-21 15:47:15

标签: nlog

问题类型:错误

摘要:当我们添加多个异步文件目标时,我正在处理一个日志繁重的服务,该服务会死锁。使用nLog版本4.5.4

时,我也注意到了相同的结果

NLog版:4.4.11

平台:。Net 4.5

当前NLog配置:存储在数据库中的XML

<nlog throwExceptions="true" internalLogFile="c:\Temp\nLog.txt">
  <variable name="Empty" value="-" />
  <extensions>
    <add assembly="Company.Diagnostics.ApplicationInsights" />
  </extensions>
  <targets>
    <target type="AsyncWrapper" name="asyncCompanyAi" overflowAction="Grow" timeToSleepBetweenBatches="0" batchSize="1000">
      <target type="CompanyAITarget" name="aiTarget" />
    </target>
    <target type="AsyncWrapper" name="asyncFile" overflowAction="Grow" timeToSleepBetweenBatches="0" batchSize="1000">
      <target name="file" type="File" fileName="${gdc:item=rootPath}\${machinename}.${gdc:item=appName}.log" archiveNumbering="Sequence" archiveAboveSize="10485760" maxArchiveFiles="10" archiveFileName="${gdc:item=rootPath}\Archives\${machinename}.${gdc:item=appName}.{#}.log" autoFlush="True">
        <layout type="LayoutWithHeaderAndFooter">
          <layout type="CsvLayout">
            <column name="Timestamp" layout="${longdate:uppercase=true:whenEmpty=${Empty}}" />
            <column name="Level" layout="${level:uppercase=true:whenEmpty=${Empty}}" />
            <column name="Logger" layout="${logger:whenEmpty=${Empty}}" />
            <column name="ThreadId" layout="${threadid:whenEmpty=${Empty}}" />
            <column name="AppName" layout="${gdc:item=appName:whenEmpty=${Empty}}" />
            <column name="OperationId" layout="${event-properties:item=RequestId:whenEmpty=${Empty}}" />
            <column name="URL" layout="${event-properties:item=URL:whenEmpty=${Empty}}" />
            <column name="DSN" layout="${event-properties:item=DSN:whenEmpty=${Empty}}" />
            <column name="UserId" layout="${event-properties:item=UserId:whenEmpty=${Empty}}" />
            <column name="LoginId" layout="${event-properties:item=LoginId:whenEmpty=${Empty}}" />
            <column name="PageId" layout="${event-properties:item=PageId:whenEmpty=${Empty}}" />
            <column name="Message" layout="${replace-newlines:${message}:whenEmpty=${Empty}}" />
            <column name="Exception" layout="${replace-newlines:${exception:format=ToString}:whenEmpty=${Empty}}" />
          </layout>
          <footer type="SimpleLayout" text="" />
        </layout>
      </target>
    </target>
    <target type="AsyncWrapper" name="qa1" overflowAction="Grow" timeToSleepBetweenBatches="0" batchSize="1000">
      <target name="file_qa1" type="File" fileName="${gdc:item=rootPath}\qa1.${machinename}.${gdc:item=appName}.log" archiveNumbering="Sequence" archiveAboveSize="20971520" maxArchiveFiles="20" archiveFileName="${gdc:item=rootPath}\Archives\qa1.${machinename}.${gdc:item=appName}.{#}.log" autoFlush="True">
        <layout type="LayoutWithHeaderAndFooter">
          <layout type="CsvLayout">
            <column name="Timestamp" layout="${longdate:uppercase=true:whenEmpty=${Empty}}" />
            <column name="Level" layout="${level:uppercase=true:whenEmpty=${Empty}}" />
            <column name="Logger" layout="${logger:whenEmpty=${Empty}}" />
            <column name="ThreadId" layout="${threadid:whenEmpty=${Empty}}" />
            <column name="AppName" layout="${gdc:item=appName:whenEmpty=${Empty}}" />
            <column name="OperationId" layout="${event-properties:item=RequestId:whenEmpty=${Empty}}" />
            <column name="URL" layout="${event-properties:item=URL:whenEmpty=${Empty}}" />
            <column name="DSN" layout="${event-properties:item=DSN:whenEmpty=${Empty}}" />
            <column name="UserId" layout="${event-properties:item=UserId:whenEmpty=${Empty}}" />
            <column name="LoginId" layout="${event-properties:item=LoginId:whenEmpty=${Empty}}" />
            <column name="PageId" layout="${event-properties:item=PageId:whenEmpty=${Empty}}" />
            <column name="Message" layout="${replace-newlines:${message}:whenEmpty=${Empty}}" />
            <column name="Exception" layout="${replace-newlines:${exception:format=ToString}:whenEmpty=${Empty}}" />
          </layout>
          <footer type="SimpleLayout" text="" />
        </layout>
      </target>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="asyncFile" />
    <logger name="*" minlevel="Warn" writeTo="asyncCompanyAi" />
    <logger name="*" minlevel="Trace" writeTo="qa1">
      <filters>
        <when condition="not equals('${uppercase:${event-properties:item=DSN}}', '${uppercase:qaEnv1}')" action="IgnoreFinal" />
        <when condition="not equals('${uppercase:${event-properties:item=LoginId}}', '${uppercase:user1}')" action="IgnoreFinal" />
      </filters>
    </logger>
  </rules>
</nlog>

如果出现BUG:当前结果是什么?

  • 添加第二个异步文件目标会导致某些日志记录重度服务死锁

从服务转储中提取以下消息:

检测到死锁 CLR线程0xb保持对SyncBlock的锁定000000c84538d1f8 OBJ:000000c4fb07dbe8 [System.Object] ...等待SyncBlock上的锁定000000c84538d4c8 OBJ:000000c4fb069e98 [System.Object] CLR线程0x10保持对SyncBlock的锁定000000c84538d4c8 OBJ:000000c4fb069e98 [System.Object] ...等待SyncBlock上的锁定000000c84538d1f8 OBJ:000000c4fb07dbe8 [System.Object] CLR线程0xb正在等待NLog.LogFactory.GetLogger(LoggerCacheKey)(+ 0x5f Native) CLR线程0x10正在等待NLog.Targets.Target.NLog.Internal.ISupportsInitialize.Initialize(NLog.Config.LoggingConfiguration)(+ 0x11 IL,+ 0x45 Native)

预期结果是什么?

  • 添加多个异步目标不应导致死锁。 (至少我认为它不应该

您是否选中了Internal log

  • 是的,内部日志记录已启用,但未导致信息性错误。

完整异常详情

从第一个帖子堆叠:

操作系统线程ID:0x7ec(13)         儿童SP IP呼叫站点 000000c84724d5e8 00007fff062c0d0a [GCFrame:000000c84724d5e8] 000000c84724d728 00007fff062c0d0a [GCFrame:000000c84724d728] 000000c84724d768 00007fff062c0d0a [HelperMethodFrame_1OBJ:000000c84724d768] System.Threading.Monitor.Enter(System.Object) 000000c84724d860 00007ffe9ca7606f NLog.LogFactory.GetLogger(LoggerCacheKey) 000000c84724d910 00007ffe9ca75ff0 NLog.LogFactory.GetLogger(System.String) 000000c84724d960 00007ffe9ca75f47 Company.Practices.Logging.NLogLogger + c__DisplayClass5.b__4(System.String) 000000c84724d9a0 00007ffefaac1774 System.Collections.Concurrent.ConcurrentDictionary 2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].GetOrAdd(System.__Canon, System.Func 2)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ Collections \ Concurrent \ ConcurrentDictionary.cs @ 1041] 000000c84724da00 00007ffe9ca75e90 Company.Practices.Logging.NLogLogger.GetLogger(System.String) 000000c84724da80 00007ffe9ca75d66 Company.Practices.Logging.NLogLogger.ShouldLog(Company.Practices.Logging.TraceLevel,System.String) 000000c84724daf0 00007ffe9ca42eb1 Company.Practices.Logging.TraceLogger.ShouldLog(Company.Practices.Logging.TraceLevel,System.String) 000000c84724db60 00007ffe9ca42dc9 Company.Practices.Logging.TraceLogger.IfShouldLog(Company.Practices.Logging.TraceLevel,System.String,System.Func 1) 000000c84724dbc0 00007ffe9ca42d47 Company.Practices.Logging.TraceLogger.IfShouldLogVerbose(System.String, System.Func 1) 000000c84724dbf0 00007ffe9ca4178b PetaPoco.Database.OnExecutingCommand(System.Data.IDbCommand) 000000c84724dc​​50 00007ffe9ca414d6 PetaPoco.Database.DoPreExecute(System.Data.IDbCommand) 000000c84724dd10 00007ffe9c6ce2f6 PetaPoco.Database.CreateCommand(System.Data.IDbConnection,System.String,System.Object []) 000000c84724ddd0 00007ffe9c6cd916 PetaPoco.Database + d__22 1[[System.__Canon, mscorlib]].MoveNext() 000000c84724df40 00007ffefaaeda64 System.Collections.Generic.List 1 [[System .__ Canon,mscorlib]] .. ctor(System.Collections.Generic.IEnumerable 1) [f:\dd\ndp\clr\src\BCL\system\collections\generic\list.cs @ 104] 000000c84724dfb0 00007ffef917a9c6 System.Linq.Enumerable.ToList[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable 1) 000000c84724dff0 00007ffe9c6ccec1 PetaPoco.Database.Fetch [[System .__ Canon,mscorlib],[System .__ Canon,mscorlib],[System .__ Canon,mscorlib]](System.Func 3, System.String, System.Object[]) 000000c84724e0c8 00007ffefbcb1f3c [StubHelperFrame: 000000c84724e0c8] 000000c84724e120 00007ffe9c6ca4ad Company.Platform.Central.Configuration.DatabaseConfigurationRepository.Get(System.String, System.String, System.Nullable 1,System.String) 000000c84724e200 00007ffe9c6c9e17 Company.Platform.Central.Configuration.DatabaseConfigurationRepository.Get(System.String) 000000c84724e260 00007ffe9c6c96fa Company.Platform.Central.Configuration.DatabaseConfigurationSource.GetSectionData(System.String,Company.Platform.Central.Configuration.ContextInformation) 000000c84724e440 00007ffe9c6c720f Company.Platform.Central.Configuration.DatabaseConfigurationSource.GetSection(System.String,Company.Platform.Central.Configuration.ContextInformation) 000000c84724e630 00007ffe9c6c6684 Company.Platform.Central.Configuration.DatabaseConfigurationSource.GetSection(System.String) 000000c84724e670 00007ffe9c6c65c4 Company.Practices.Configuration.ConfigurationSourceBase.GetSection [System .__ Canon,mscorlib] 000000c84724e6e0 00007ffe9c6c64d8 Company.Practices.Configuration.ConfigurationSourceBase.TryGetSection [[System .__ Canon,mscorlib]](System.String,System .__ Canon ByRef) 000000c84724e760 00007ffe9c6c621e Company.Diagnostics.ApplicationInsights.ApplicationInsights.get_ConfigurationSection() 000000c84724e7a0 00007ffe9cb90724 Company.Diagnostics.ApplicationInsights.TelemetryLogger.CreateTelementryClient(Company.Common.UserInfo) 000000c84724e7f0 00007ffe9cb8fa55 Company.Diagnostics.ApplicationInsights.TelemetryLogger.TrackTrace(Company.Common.UserInfo,System.String,Microsoft.ApplicationInsights.DataContracts.SeverityLevel,System.Collections.Generic.Dictionary 2) 000000c84724e840 00007ffe9cb8ea99 NLog.Targets.Target.Write(NLog.Common.AsyncLogEventInfo) 000000c84724e880 00007ffe9cb8e94b NLog.Targets.Target.Write(System.Collections.Generic.IList 1) 000000c84724e8e0 00007ffe9cb82564 NLog.Targets.Target.WriteAsyncThreadSafe(System.Collections.Generic.IList 1) 000000c84724e960 00007ffe9cb82286 NLog.Targets.Target.WriteAsyncLogEvents(System.Collections.Generic.IList 1) 000000c84724ea50 00007ffe9cb74522 NLog.Targets.Wrappers.AsyncTargetWrapper.WriteEventsInQueue(Int32,System.String) 000000c84724eac0 00007ffe9cb7425b NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(System.Object) 000000c84724eb20 00007ffefab04750 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 954] 000000c84724ebf0 00007ffefab045e4 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 902] 000000c84724ec20 00007ffefab7389a System.Threading.TimerQueueTimer.CallCallback()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ timer.cs @ 705] 000000c84724ec80 00007ffefab73688 System.Threading.TimerQueueTimer.Fire()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ timer.cs @ 662] 000000c84724ecf0 00007ffefab7f5d7 System.Threading.TimerQueue.FireNextTimers()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ timer.cs @ 417] 000000c84724f168 00007ffefbcb5a03 [DebuggerU2MCatchHandlerFrame:000000c84724f168]

来自第二线程的筹码:

操作系统线程ID:0x868(18)         儿童SP IP呼叫站点 000000c84844bff8 00007fff062c0d0a [GCFrame:000000c84844bff8] 000000c84844c138 00007fff062c0d0a [GCFrame:000000c84844c138] 000000c84844c178 00007fff062c0d0a [HelperMethodFrame_1OBJ:000000c84844c178] System.Threading.Monitor.Enter(System.Object) 000000c84844c270 00007ffe9ca711d5 NLog.Targets.Target.NLog.Internal.ISupportsInitialize.Initialize(NLog.Config.LoggingConfiguration) 000000c84844c2d0 00007ffe9ca6f01a NLog.Config.LoggingConfiguration.InitializeAll() 000000c84844c340 00007ffe9ca58b13 NLog.LogFactory.ReconfigExistingLoggers() 000000c84844c3b0 00007ffe9ca58a39 NLog.LogFactory.set_GlobalThreshold(NLog.LogLevel) 000000c84844c410 00007ffe9ca5720a NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLog.Config.NLogXmlElement,System.String,Boolean) 000000c84844c540 00007ffe9ca56b2e NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLog.Config.NLogXmlElement,System.String,Boolean) 000000c84844c590 00007ffe9ca56548 NLog.Config.XmlLoggingConfiguration.Initialize(System.Xml.XmlReader,System.String,Boolean) 000000c84844c5f0 00007ffe9ca55f2a NLog.Config.XmlLoggingConfiguration..ctor(System.Xml.XmlReader,System.String) 000000c84844c640 00007ffe9ca52be1 Company.Practices.Logging.NLogLogger.LoadConfig(System.String) 000000c84844c9e0 00007ffe9ca4216c Company.Practices.Logging.TraceLogger.ReloadLoggingSettings() 000000c84844cb40 00007ffe9cb8eff5 Company.Practices.Logging.TraceLogger.b__1(System.Object,System.EventArgs) 000000c84844cda8 00007ffefbcb5a03 [DebuggerU2MCatchHandlerFrame:000000c84844cda8] 000000c84844d0e8 00007ffefbcb5a03 [HelperMethodFrame_PROTECTOBJ:000000c84844d0e8] System.RuntimeMethodHandle.InvokeMethod(System.Object,System.Object [],System.Signature,Boolean) 000000c84844d260 00007ffefaabf8f2 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object,System.Object [],System.Object [])[f:\ dd \ ndp \ clr \ src \ BCL \ system \ reflection \ methodinfo.cs @ 761] 000000c84844d2d0 00007ffefaaeb419 System.Delegate.DynamicInvokeImpl(System.Object [])[f:\ dd \ ndp \ clr \ src \ BCL \ system \ delegate.cs @ 123] 000000c84844d320 00007ffe9cb8efa6 Company.EventRaiser.InvokeDelegate(System.Delegate,System.Object []) 000000c84844d390 00007ffe9c6a046a Company.EventRaiser.UnsafeRaise(System.Delegate,System.Object []) 000000c84844d410 00007ffe9c6a0380 Company.EventRaiser.Raise(System.EventHandler,System.Object,System.EventArgs) 000000c84844d470 00007ffe9c6a0264 Company.Practices.Configuration.ConfigurationSourceManager.set_Current(Company.Practices.Configuration.IConfigurationSource) 000000c84844d4f0 00007ffe9cb8e348 Company.Platform.Central.Services.CompanyMarketingService 1[[System.__Canon, mscorlib]]..ctor(System.String, System.Type) 000000c84844d788 00007ffefbcb5a03 [DebuggerU2MCatchHandlerFrame: 000000c84844d788] 000000c84844dac8 00007ffefbcb5a03 [HelperMethodFrame_PROTECTOBJ: 000000c84844dac8] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean) 000000c84844dc40 00007ffefaada68f System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) [f:\dd\ndp\clr\src\BCL\system\reflection\ConstructorInfo.cs @ 753] 000000c84844dcc0 00007ffefaaf678f System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Threading.StackCrawlMark ByRef) [f:\dd\ndp\clr\src\BCL\system\rttype.cs @ 5279] 000000c84844dd70 00007ffefaaf627a System.Activator.CreateInstance(System.Type, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[]) [f:\dd\ndp\clr\src\BCL\system\activator.cs @ 107] 000000c84844ddf0 00007ffefb36d845 System.Activator.CreateInstanceFromInternal(System.String, System.String, Boolean, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Security.Policy.Evidence) [f:\dd\ndp\clr\src\BCL\system\activator.cs @ 441] 000000c84844de40 00007ffefb332276 System.AppDomain.CreateInstanceFromAndUnwrap(System.String, System.String, Boolean, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[]) [f:\dd\ndp\clr\src\BCL\system\appdomain.cs @ 4655] 000000c84844dea0 00007ffe9cb8dcbf Company.Reflection.TypeConstructor.CreateInstance(System.AppDomain) 000000c84844df60 00007ffe9cb8db6b Company.Reflection.TypeConstructor.CreateInstance[[System.__Canon, mscorlib]](System.AppDomain) 000000c84844dfd0 00007ffe9cb8cfb4 Company.Services.Subservices.SubserviceController.LoadSubservice() 000000c84844e130 00007ffe9cb8bd10 Company.Services.ServiceRunnerInstance+c__DisplayClassd.b__5(Company.Services.Subservices.SubserviceController) 000000c84844e2b0 00007ffefb4dafec System.Threading.Tasks.Parallel+c__DisplayClass17_0 1 [[System .__ Canon,mscorlib]]。b _1()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Parallel.cs @ 1193] 000000c84844e370 00007ffefb4ca260 System.Threading.Tasks.Task.InnerInvokeWithArg(System.Threading.Tasks.Task)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2899] 000000c84844e3a0 00007ffefb598f72 System.Threading.Tasks.Task + c__DisplayClass176_0.b__0(System.Object)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2624] 000000c84844e410 00007ffefab04750 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 954] 000000c84844e4e0 00007ffefab045e4 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 902] 000000c84844e510 00007ffefab2c928 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2827] 000000c84844e5c0 00007ffefab2c063 System.Threading.Tasks.Task.ExecuteEntry(Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2767] 000000c84844e600 00007ffefab30463 System.Threading.Tasks.ThreadPoolTask​​Scheduler.TryExecuteTaskInline(System.Threading.Tasks.Task,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ ThreadPoolTask​​Scheduler.cs @ 92] 000000c84844e650 00007ffefab3033b System.Threading.Tasks.TaskScheduler.TryRunInline(System.Threading.Tasks.Task,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ TaskScheduler.cs @ 219] 000000c84844e6f0 00007ffefb4c94a7 System.Threading.Tasks.Task.InternalRunSynchronously(System.Threading.Tasks.TaskScheduler,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 1219] 000000c84844e780 00007ffefb4d6592 System.Threading.Tasks.Parallel.ForWorker [[System .__ Canon,mscorlib]](Int32,Int32,System.Threading.Tasks.ParallelOptions,System.Action 1, System.Action 2,System.Func {{1} 1,System.Action 4, System.Func 1,System.Threading.Tasks.ParallelOptions,System.Action 1) [f:\dd\ndp\clr\src\BCL\system\threading\Tasks\Parallel.cs @ 1264] 000000c84844e860 00007ffefb4d78df System.Threading.Tasks.Parallel.ForEachWorker[[System.__Canon, mscorlib],[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable 2,System.Action 1, System.Action 4,System.Func 3, System.Func 1 ,System.Action 5, System.Func 1,System.Action`1)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Parallel.cs @ 1674] 000000c84844e9c0 00007ffe9cb8190c Company.Services.ServiceRunnerInstance.StartSubservices() 000000c84844ea90 00007ffefab2c686 System.Threading.Tasks.Task.Execute()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2498] 000000c84844ead0 00007ffefab04750 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 954] 000000c84844eba0 00007ffefab045e4 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ executioncontext.cs @ 902] 000000c84844ebd0 00007ffefab2c928 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2827] 000000c84844ec80 00007ffefab2c063 System.Threading.Tasks.Task.ExecuteEntry(Boolean)[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ Tasks \ Task.cs @ 2767] 000000c84844ecc0 00007ffefab0f74e System.Threading.ThreadPoolWorkQueue.Dispatch()[f:\ dd \ ndp \ clr \ src \ BCL \ system \ threading \ threadpool.cs @ 820] 000000c84844f158 00007ffefbcb5a03 [DebuggerU2MCatchHandlerFrame:000000c84844f158]

有任何解决方法吗?

  • 目前是的,解决方法是尽可能少地运行目标。

**是否有适用的版本? **

  • 不,我试图使用最新的nLog版本进行测试,但我仍然看到该版本的问题。

您可以通过编写单元测试来帮助我们吗?

  • 当然,如果你知道修复后你可以指出我正确的方向。很乐意提供帮助!

1 个答案:

答案 0 :(得分:0)

我不认为问题是异步FileTargets。我认为问题是你自己的自定义目标:

<target type="AsyncWrapper" name="asyncCompanyAi" overflowAction="Grow" timeToSleepBetweenBatches="0" batchSize="1000">
  <target type="CompanyAITarget" name="aiTarget" />
</target>

通过在自定义目标中使用NLog-Logger,您似乎打破了NLog的不成文规则:

NLog.LogFactory.GetLogger(System.String)
Company.Practices.Logging.NLogLogger.GetLogger(System.String) 
Company.Practices.Logging.TraceLogger.IfShouldLogVerbose(System.String, System.Func1) 
PetaPoco.Database.OnExecutingCommand(System.Data.IDbCommand) 000000c84724dc50 
PetaPoco.Database.CreateCommand(System.Data.IDbConnection, System.String, System.Object[]) 
Company.Platform.Central.Configuration.DatabaseConfigurationRepository.Get(System.String) 000000c84724e260 00007ffe9c6c96fa 
Company.Diagnostics.ApplicationInsights.TelemetryLogger.CreateTelementryClient(Company.Common.UserInfo) 000000c84724e7f0 00007ffe9cb8fa55 
Company.Diagnostics.ApplicationInsights.TelemetryLogger.TrackTrace(Company.Common.UserInfo, System.String, Microsoft.ApplicationInsights.DataContracts.SeverityLevel, System.Collections.Generic.Dictionary2)
NLog.Targets.Target.WriteAsyncThreadSafe(System.Collections.Generic.IList1)

您应该只在自定义目标中使用NLog.Common.InternalLogger。

P.S。您还应该调查您拨打此电话的原因:

Company.Practices.Logging.TraceLogger.ReloadLoggingSettings() 

在运行时重新加载整个NLog配置会产生巨大的开销。