Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: RollingFileAppender generates unexpected filename and/or causes IIS to hang
Prev Next
You are not authorized to post a reply.

Author Messages
Iyer, Devan

09/16/2008 10:08 PM  
We are using rolling file appender in an IIS managed C# application. Our log4Net deployment is configured with the following options specified in basic.xml: <appendToFile value="false" /> <countDirection value="0" /> <maximumFileSize value="512KB" /> <maxSizeRollBackups value="100" /> <rollingStyle value="Once" /> <staticLogFileName value="false" />. The file pattern for our log file name is "abc_%date{yyyyMMdd_HHmmss}_%processid_.log".
We have observed in our production environment that occasionally filenames would be created with patterns like "abc_%date{yyyyMMdd_HHmmss}_%processid_.log.1", "abc_%date{yyyyMMdd_HHmmss}_%processid_.log.1.2", "abc_%date{yyyyMMdd_HHmmss}_%processid_.log.1.2.3", etc. We have observed filenames with the dot+sequential numbers pattern after the .log to be anything from ".1" to ".220". This is one of two unexpected behaviours observed.
 
The second unexpected behaviour seems to a special case of the first that occasionally causes IIS to hang (100% CPU consumption). An analysis of several crash dumps taken at the time of the hang indicated that RollingFileAppender had in memory a filename of the same pattern as above but with the number of characters [base filename pattern]+[recurring extension pattern] exceeding 255 characters. It is very likely that an attempt to create a file by such name on NTFS would throw exceptions at various levels - managed and native - and hence the file itself is never created.
 
To the best of our knowledge, there were no events to trigger the filename to be rolled. As indicated in the configuration options, we are using RollingStyle of "Once". (The log file content is minimal at the time the symptoms occur - total file size is about 2K - and the times of occurrence are totally non related).
 
We have been unable to capture the workflow leading up to the symptoms above due to the high number of users and document types in our production environment. The permissions on the logging folder are static. However, we have found a simple workflow in our lab environment, using permissions, that produce similar symptoms. This workflow is:
 
- Right click on the logging folder and select "Properties"
- Under the "Security" tab ensure that IIS_WPG group doesn't have write access to the logging folder.
- Restart IIS
- Launch our application and view a document.  Check the logging folder to make sure that a logfile is not created.
View a few more documents
- Change the permission on the logging folder and ensure IIS_WPG group has write access to the folder.  DO NOT restart IIS after changing the permission.
- Launch our application and view another document.
- At this point a logfile with a filename pattern described will be found in the logging folder.
 
As mentioned, it is unlikely that permissions are the trigger in our event but it is likely that the same code is creating these unexpected patterns irrespective of the trigger.
Georg Jansen

09/18/2008 8:49 PM  

Iyver,

 

 You use:

 appendToFile=false (I always want a new file)

And you have RollingStyle=Once (this by default sets the appendToFile to false)

 What I think happen is that every time log4Net needs to open a log file it opens a new file (whenever a worker process starts), and that is the reason for the sequential thing, are you sure you don’t want RollingStyle=Date?

 But I am uncertain about the kind of naming schema you try to accomplish? Maybe you could explain it  - it would make it easier to make a proposal.

 

You also use the %processId as a part of the filename pattern. I just want to mention that as far as I know you will have one processeId for each worker process (can be several depending on the setup). Requests from the same client can be served by different worker processes – this could possibly make it hard to follow one client through the logs (if you need that).

 

Best regards

Georg

http://www.l4ndash.com – log4net dashboard

 

Iyer, Devan

09/24/2008 10:09 PM  
I solved this one:

This behaviour is due to RollingFileAppender and it's base class FileAppender not resetting certain private member variables when an OpenFile call fails.

RollingFileAppender.OpenFile (filename, bAppend) always does a GetNextOutputFileName(fileName) before calling the base class OpenFile. This appends the string value of m_curSizeRollBackups to filename.
 
FileAppender.OpenFile (filename, bAppend) stores in private member variables the value of the arguments filename and bAppend and then attempts to create a LockingStream. This fails with a LockStateException which is not handled. The correct approach would be to roll back the values of m_fileName, m_appendToFile , m_curSizeRollBackups and m_scheduledFilename when the OpenFile call fails. I accomplished this in my subclass as follows:
 
    protected override void <MyClass>OpenFile(string fileName, bool append)
    {
        bool oldAppend = this.AppendToFile;
        string oldFileName = this.File;
 
        try
        {
            base.OpenFile (fileName, append);
        }
        catch (log4net.Core.LogException ex)
        {
            LogLog.Debug ("CERollingFileAppender.OpenFile, base.OpenFile (fileName, append) threw an exception, " + ex.Message);
            base.File = oldFileName;    // easily set by protected property access
            base.AppendToFile = oldAppend;    // easily set by protected property access
            base.ExistingInit ();    // no access to m_curSizeRollBackups and m_scheduledFilename but this will do it.
        }
    }
Ideally this fix should be in the core RollingFileAppender, FileAppender implementations with appropriate additional configuration status checks.
 
You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > RollingFileAppender generates unexpected filename and/or causes IIS to hang



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement