You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Jeff Patzner <Je...@FBLFinancial.com> on 2008/04/28 17:52:12 UTC

log4net Memory Leak


We are currently experiencing  a reproducible memory leak in a C# .NET Web
Service. When we analyze the memory using WinDBG, are are able to find
loads and loads of strings containing the information that we are logging
in our Web Service. So each time we write to the log, that string is stuck
in the memory for our aspnet_wp process. We have verified this by dumping
the actual string objects and finding the data that we logged.

We have included below our configuration, our global.asax snippet, and also
a snippet of our source code to demonstrate how we are utilizing log4net.

***Our configuration***

<log4net>

    <appender name="AWD2FNLogger"
type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="c:\\AWD2FNLog.log" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="20" />
      <!-- uncomment to set maximum file size limit <param
name="MaximumFileSize" value="100MB" />-->
      <param name="RollingStyle" value="Date" />
      <param name="StaticLogFileName" value="false" />
      <param name="LockingModel" value="MinimalLock"/>
      <param name="DatePattern" value="MM-dd-yyyy"/>

      <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p - %m%n" />
      </layout>

   </appender>

    <!-- Setup the root category, add the appenders and set the default
priority -->

    <root>
      <priority value="DEBUG" />
      <appender-ref ref="AWD2FNLogger" />
    </root>

  </log4net>


****Our Global.asax snippet*****

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        log4net.Config.XmlConfigurator.Configure();

    }


****our code snippet******

using log4net;
using log4net.Config;


public class AWD2FN : System.Web.Services.WebService
{
private static readonly ILog mylog =
LogManager.GetLogger("RollingLogFileAppender");
 public AWD2FN () {
        BasicConfigurator.Configure();
                             }
}




    [WebMethod]
    public FNReturn AddDocument(string FileLocation, FNProp[] Properties,
string DocClass)
    {

        //create an instance of our helper class procs
        Procs myProcs = new Procs();

        //get the calling IP of the client so we can distinguish them
        string strCallingIP;
        strCallingIP = myReq.ServerVariables["REMOTE_ADDR"];

        //and the logging begins
        mylog.Info("Calling IP: " + strCallingIP + "; Entering AddDocument.
FileLocation: " + FileLocation + ", DocClass: " + DocClass
            + ", Properties: \r\n" +
myProcs.DumpProps(Properties).ToString() );

        //create a FNReturn object and a FNETAdd object
        //the constructor of the FNETAdd takes in all the parameters
        //the doAdd function returns a FNReturn object
        FNReturn fnrAdd;
        FNETAdd objAdd;
        fnrAdd = new FNReturn();
        objAdd = new FNETAdd(DocClass, FileLocation, Properties,
fnuAWD2FN);
        fnrAdd = objAdd.DoAdd();

        if (fnrAdd.Status == "Success")
        {
            //we have successfully added the document
            mylog.Info("Calling IP: " + strCallingIP + "; Leaving
AddDocument. Status: " + fnrAdd.Status + ", Value: " + fnrAdd.Value + "
SessionID: " + fnrAdd.LogonID);
        }
        else
        {
            //adding of the document failed
            mylog.Error("Calling IP: " + strCallingIP + "; Leaving
AddDocument. Status: " + fnrAdd.Status + ", Value: " + fnrAdd.Value + "
SessionID: " + fnrAdd.LogonID);
            if (fnrAdd.LogonID != "")
            {
                //let's add this to the session management so this session
can
                //be removed with the logoffall function call
                AddSession(fnuAWD2FN.superuser, fnrAdd.LogonID);
            }

        }

        return fnrAdd;
    }

__________________________________________
The information contained in this message may be privileged and
confidential and protected from disclosure. If you are not the intended
recipient of this message, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly prohibited. If
you have received this communication in error, please notify us immediately
by replying to the message, and please delete it from your computer.