Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net became very slow with caller location information after Windows 10 Fall Creators Update (1709)

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.

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.");
        }
    }
}

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.

Results before Windows update (1709)

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

Results after Windows update (1709)

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!

like image 962
Jezze Avatar asked Oct 17 '25 10:10

Jezze


1 Answers

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.

like image 78
Marc Avatar answered Oct 19 '25 09:10

Marc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!