[prev in list] [next in list] [prev in thread] [next in thread]
List: log4net-user
Subject: RE: Rolling Based on Size not working
From: "Nicko Cadell" <nicko () neoworks ! com>
Date: 2005-08-31 8:20:55
Message-ID: DDEB64C8619AC64DBC074208B046611C76946B () kronos ! neoworks ! co ! uk
[Download RAW message or body]
Shaily,
Change your layout to use writer.Write rather than WriteLine.
It looks like this is a bug where the CountingQuietTextWriter isn't
counting strings written with WriteLine.
Cheers,
Nicko
> -----Original Message-----
> From: Shaily Goel [mailto:gshaily@novell.com]
> Sent: 31 August 2005 07:36
> To: log4net-user@logging.apache.org; Nicko Cadell
> Subject: RE: Rolling Based on Size not working
>
> hi
>
> I have found that the problem is with LayOut. I made my own
> layOut called as "MineSimpleLayout". For testing this LayOut
> just writes one constant string.
> It is implemented in following way:
>
> public class MineSimpleLayout: LayoutSkeleton
> {
>
> public MineSimpleLayout()
> {
> this.IgnoresException = true;
> }
>
> override public void ActivateOptions()
> {
> // nothing to do.
> }
>
> override public void Format(TextWriter writer, LoggingEvent
> loggingEvent)
> {
>
>
> string formatString = null;
> if(loggingEvent == null)
> {
> return;
> }
> formatString = "Test Message LayOut";
> writer.WriteLine(formatString);
>
>
> }
> }
>
> Results: I found that if I associate RollingFileAppender to
> "MineSimpleLayout" it does not roll the file. It go on
> writing to single file and value of variable
> "((CountingQuietTextWriter)QuietWriter).Count
> " is never changed.
> My idea is that the above "Format method" automatically
> close the writer Object. So the Property
> "((CountingQuietTextWriter)QuietWriter).Count" always shows
> 0. But If I add the following line of code to Format method "
> loggingEvent.WriteRenderedMessage(writer);" then it works properly.
>
> I do not want to do "loggingEvent.WriteRenderedMessage" as in
> practical scenario my logging event will be some "object" and
> not string and so I do not want to write RenderedMessage to Writer.
>
> My requirement is : I want to make "CustomLayOut" which reads
> the LoggingEvent Object . Extract various property values
> from it. Make the Formatted String and write that string to File.
>
> Please help me in making such kind of layOut and associating
> that LayOut with RollingFileAppender.
>
> Thanks
> Shaily
>
>
>
>
> >>> nicko@neoworks.com 08/30/05 8:44 PM >>>
>
> 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
> >
> >
> >
> >
>
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic