logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Wachsmann <e...@flex-radio.com>
Subject log4net Memory Leak
Date Mon, 19 Oct 2015 18:53:16 GMT
While I am sure that it is a result of misconfiguration, I have a memory
leak issue while using log4net that I wondered if someone here could help
me resolve.  We are using log4net to log serial data in our application to
a file.  Because the calls for the serial port always come from the same
class, we are less interested in the class/function and more interested in
which COM port sent/received the data and what was in the data.  As such,
we pass one logger object around to be used by multiple serial port.

Running Regate ANTS memory profiler, it finds that the memory is piling up
in the form of strings that aren't released after calling the log4net Debug
function.  If I comment the 2 calls to logger.Debug, the memory becomes
stable in the same environment.  Can someone help me figure out what I'm
doing wrong here?  Below is our config setup.  Thanks.


Eric Wachsmann


==================
private ILog logger;

private void LoggerSetup()
        {
            logger =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();
            //patternLayout.ConversionPattern = "%date [%thread] %-5level
%logger - %message%newline";
            patternLayout.ConversionPattern = "%date{yyyy-MM-dd HH:mm:ss}
%message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();
            roller.AppendToFile = true;
            roller.File =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"[company\LogFiles\[application].log");
            roller.Layout = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize = "5MB";
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();
            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }

Mime
View raw message