Windows 10 Fall Creators Update(1709)之后,log4net的呼叫者位置信息变得非常缓慢 [英] log4net became very slow with caller location information after Windows 10 Fall Creators Update (1709)

查看:110
本文介绍了Windows 10 Fall Creators Update(1709)之后,log4net的呼叫者位置信息变得非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道log4net的文档指出,呼叫者位置信息的记录可能非常慢,除非不影响软件的性能,否则不应该使用它.

I known that the documentation of log4net points out that the logging of caller location information can be very slow and shouldn't be used unless the performance of the software is not affected.

情况一直如此,直到Windows 10 Fall Creators Update.这是一个小示例项目.

And until the Windows 10 Fall Creators Update this was the case. Here is a small example project.

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
    </configSections>

    <log4net>
        <appender name="DefaultAppender" type="log4net.Appender.RollingFileAppender">
            <file value="logging.log" />
            <encoding value="utf-8" />
            <appendToFile value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <!--without caller location information-->
                <!--<conversionPattern value="%d | %-5p | %t | %m%n" />-->
                <!--with caller location information-->
                <conversionPattern value="%d | %-5p | %t | %C.%M:%L | %m%n" />
            </layout>
        </appender>
        <root>
          <level value="All" />
          <appender-ref ref="DefaultAppender" />
        </root>
    </log4net>

    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>

Program.cs

using System;
using System.Diagnostics;
using log4net;

namespace Log4Net.CSharp
{
    class Program
    {
        private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        static void Main(string[] args)
        {            
            LoggingTest(1000);

            Console.ReadKey();
        }

        private static void LoggingTest(int iterations)
        {
            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                Log.Info("Some info logging.");
            }

            Console.WriteLine($"Logging of {iterations} iterations took: {sw.ElapsedMilliseconds} ms.");
        }
    }
}

在Windows更新(1709)之后,使用呼叫者位置信息(如%C%M%L)的性能大约要比不使用它的性能差100倍.问题肯定与更新有关,因为回滚后性能恢复正常.

After the Windows update (1709) the performance with caller location information like %C %M %L is about 100 times worse than without. The problem is definitely related to the update because after a rollback the performance is back to normal.

Windows更新之前的结果(1709)

不带%C%M%L:记录1000次迭代所需的时间:18毫秒.
w%C%M%L:记录了1000次迭代:81毫秒.

w/o %C %M %L: Logging of 1000 iterations took: 18 ms.
w %C %M %L: Logging of 1000 iterations took: 81 ms.

Windows更新(1709)后的结果

不带%C%M%L:记录1000次迭代所需的时间:14毫秒.
w%C%M%L:记录了1000次迭代:1502毫秒.

w/o %C %M %L: Logging of 1000 iterations took: 14 ms.
w %C %M %L: Logging of 1000 iterations took: 1502 ms.

任何人都可以确认这个问题或知道发生了什么吗?

Can anybody confirm this problem or has an idea what's going?

对于任何有关调试/修复它的建议,我深表感谢.预先感谢!

I am grateful for any advice how to debug/fix it. Thanks in advance!

推荐答案

Microsoft更新了几天前提到的文章(

Microsoft has updated the article mentioned some days ago (https://support.microsoft.com/en-us/help/4057154/performance-of-system-diagnostics-stackframe-degrades-in-windows-10-17), and as Jeeze says in a comment the new update (https://support.microsoft.com/en-us/help/4058258) solves the problem independently of the .NET Framework used.

这篇关于Windows 10 Fall Creators Update(1709)之后,log4net的呼叫者位置信息变得非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆