logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Rolling Based on Size not working
Date Tue, 30 Aug 2005 15:14:28 GMT
Shaily,

I have tried to reproduce your situation using the code you supplied,
however it is working correctly for me. The files are size rolled at
just over 1KB in size. The exact code I am running is below. The only
significant change I have made is to use the SimpleLayout as I don't
have a copy of your MineSimpleLayout class.

This functionality should work OK with log4net 1.2.9.

Nicko


private static void ShailyGoel_Main()
{
  ILog logger = LogManager.GetLogger("TestLogger");
  log4net.Repository.Hierarchy.Logger log = logger.Logger as
log4net.Repository.Hierarchy.Logger;
  log.Level = Level.Info;
  log.Additivity = false;
  log.Repository.Configured = true; 
  log.AddAppender(ShailyGoel_CreateRollingFileAppender());

  logger.Error("This is test message: ");
  for(int i = 0; i<= 10000; i++)
  {
    logger.Error("This is new test message: " );
  }
}

private static RollingFileAppender
ShailyGoel_CreateRollingFileAppender()
{
  RollingFileAppender appender = new RollingFileAppender();

  appender.Name = "CustomRoller";
  appender.File = "C:\\tmp\\roller.txt";
  appender.AppendToFile = true;           
  appender.RollingStyle = RollingFileAppender.RollingMode.Size;

  appender.MaxSizeRollBackups = 5;
  appender.MaximumFileSize = "1KB";
  SimpleLayout layOut = new SimpleLayout();
  appender.Layout = layOut;
  appender.StaticLogFileName = true;
  appender.ActivateOptions();

  return appender;
} 

> -----Original Message-----
> From: Shaily Goel [mailto:gshaily@novell.com] 
> Sent: 30 August 2005 14:10
> To: log4net-user@logging.apache.org; Nicko Cadell
> Subject: Rolling Based on Size not working
> 
> hi
>  
> I am facing the following problem while using RollingFileAppender:
> version of Log4net used: incubating-log4net-1.2.9-beta ; 
> Platform: Windows 
> 
> Following is the code which I am running:
>  
> class TestRollingFileAppender
>  {
>   /// <summary>
>   /// The main entry point for the application.
>   /// </summary>
>   [STAThread]
>   static void Main(string[] args)
>   {
>             log4net_Logger log = 
> LogManager.GetLogger("TestLogger").Logger as log4net_Logger;
>             log.Level = Level.Info;
>             log.Additivity = false;
>             log.Repository.Configured = true; 
>             log.AddAppender(CreateRollingFileAppender());
>             ILog logger = LogManager.GetLogger("TestLogger");
>             logger.Error("This is test message: ");
>             for(int i = 0; i<= 10000; i++)
>             {
>                 logger.Error("This is new test message: " );
>             }
>  
>   }
>  
>         private static RollingFileAppender CreateRollingFileAppender()
>         {
>            RollingFileAppender appender = new RollingFileAppender();
>             MineSimpleLayout layOut = new MineSimpleLayout();
>             appender.Name = "CustomRoller";
>             appender.File = "C:\\TestFolder\\Roll\\roller.txt";
>             appender.AppendToFile = true;           
>             appender.RollingStyle = 
> RollingFileAppender.RollingMode.Size;            
>                appender.MaxSizeRollBackups = 5;
>              appender.MaximumFileSize = "1KB";
>                 appender.Layout = layOut;
>                appender.StaticLogFileName = true;
>             appender.ActivateOptions();    
>             return appender;
>         }
>         
>  
>  }
>  
> Scenario 1: No Log File is existing: Running the application 
> for the first time:
>  
> I saw that when I ran my application for the first time, the 
> rolling file appender does not roll the logs. It goes on 
> appending the logs in current File (even when FileSize 
> exceeds the  MaximumFileSize i.e. 1 KB in above case)
>  
> I digged into the code of Log4net.RollingFileAppender and 
> found that it is never going into the method RollOverSize().
> The following condition in Append method:
> if ((File != null) && 
> ((CountingQuietTextWriter)QuietWriter).Count >= m_maxFileSize) 
>     {
>      RollOverSize();
>     }
> 
> always returns false.
>  
> I checked the value of 
> ((CountingQuietTextWriter)QuietWriter).Count . It is 0 for 
> every Log message. This means that value of 
> ((CountingQuietTextWriter)QuietWriter).Count  is not 
> increasing as the messages are getting appended in file and 
> file size increasing.
>  
> Scenario 2: When the Log File is already existing
>  
> I found that at the start it checks the size of already 
> existing file and properly set the value of 
> ((CountingQuietTextWriter)QuietWriter).Count equal to FileSize.
> Now when the message is logged and if  the value of  
> ((CountingQuietTextWriter)QuietWriter).Count is greater then 
> m_maxFileSize  the File is rolled properly and 
> (CountingQuietTextWriter)QuietWriter).Count  is again set to 
> "0". Now The new messages are being written into the current 
> file but as ((CountingQuietTextWriter)QuietWriter).Count  is 
> never increasing so "No" Rolls takes place after that.
>  
> Conclusion : ((CountingQuietTextWriter)QuietWriter).Count  is 
> only set at initial time of application. After that it never 
> increments as the size of file grows.
>  
> My requirement is as the FileSize grows above the particular 
> limit the Roll of file should be taken.
>  
> Please let me know if this is bug in Log4net or I am missing 
> some thing.
>  
> Thanks
> Shaily
> 
>  
> 
> 

Mime
View raw message