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: Help me with dinamically setting up the RollingFileAppender please
Prev Next
You are not authorized to post a reply.

Author Messages
Pavel Bazanov

10/27/2008 11:16 AM  

Hello,

 I have just downloaded the log4net and I can't use the RollingFileAppender. Check my code please:

// ###################################################################

var appender = new log4net.Appender.RollingFileAppender();

appender.AppendToFile = true;

appender.File = "log.txt";

appender.MaxFileSize = 10000;

appender.MaxSizeRollBackups = 10;

appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;

log4net.Config.BasicConfigurator.Configure(appender);

log.Info("event occurred");

// ###################################################################

No errors produced, but no log file is created, it just looks like nothing happens.

What am I doing wrong?

Thank you in advance.

 
Francine Taylor

10/27/2008 4:39 PM  

This is the code which I use to create a rolling file appender.

 

       public static RollingFileAppender GetRollingFileAppender(string pFilename, Level pLevel, string pPattern) {

            RollingFileAppender fileAppender = new RollingFileAppender();

            fileAppender.File = pFilename;

            if (!string.IsNullOrEmpty(pPattern)) {

                GetPatternLayout(pPattern);

            }

            else {

                fileAppender.Layout = new SimpleLayout();

            }

            fileAppender.ImmediateFlush = true;

            fileAppender.RollingStyle = RollingFileAppender.RollingMode.Size;

            fileAppender.MaximumFileSize = "10MB";

            fileAppender.AppendToFile = true;               // default to append mode

            fileAppender.MaxSizeRollBackups = 4;

            if (pLevel != null) {

                fileAppender.Threshold = pLevel;

            }

            fileAppender.ActivateOptions();

            return fileAppender;

        }

        public static PatternLayout GetPatternLayout(string pPattern) {

            PatternLayout patternLayout = new PatternLayout(pPattern);

            patternLayout.ActivateOptions();

            return patternLayout;

        }

 
Ron Grabowski

10/27/2008 10:15 PM  
You probably need to call appender.ActivateOptions() before calling Configure().
 
Pavel Bazanov

10/28/2008 4:41 PM  
Thank you for your replies.
 
Yes, I had to call appender.ActivateOptions() before calling Configure() and additionally I had to set appender.Layout. Now it works.
Btw, don't you think the design is not intuitive enough. How should I know that I have to set Layout and call ActivateOptions()? I read quite much on log4net site, but I didn't see good examples of using dynamical setting.
Don't you think it would be better if ActivateOptions() was called automatically in Configure() method and Layout had a default value?
What we have now is - if you don't know all the details - logging just will not work without any helping messages.
 
You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Help me with dinamically setting up the RollingFileAppender please



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