我在 NLog 库中使用这个方法有问题:NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state)
它消耗了太多的CPU时间。我使用 Nlog 运行了很长时间的 Windows 服务,两天后我的服务消耗了超过 80% 的 CPU 时间(一个核心几乎是 80%,第二个是 30%)。这不是 100% 的 cpu 时间,但它正在改变,在 cca 2 小时后恢复正常。所以我运行了探查器,这个方法可能导致它:NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state)
我有 10 个文件目标都设置为异步。事实上,我在我的应用程序中有很多日志记录,但仅限于 Trace 级别,如果我切换到 Info 级别,它没有帮助。
你能帮我吗,我应该减少我应用程序的登录吗?
最佳答案
根据 this thread 我也猜想为 timeToSleepBetweenBatches 设置一个更高的数字应该减少高CPU时间。似乎 NLog 的 2.0 beta 应该通过一次只运行一个惰性编写器线程来修复此行为。
与此同时,您无需更改源代码即可更改 timeToSleepBetweenBatches .您可以在 configuration file 中设置它:
<targets>
<target xsi:type="AsyncWrapper"
name="String"
queueLimit="Integer"
timeToSleepBetweenBatches="Integer"
batchSize="Integer"
overflowAction="Enum">
<target xsi:type="wrappedTargetType" ...target properties... />
</target>
</targets>
Buffering Options
timeToSleepBetweenBatches - Time in milliseconds to sleep between batches.Integer Default: 50
关于c# - NLog CPU 性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5078840/