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.
| 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. |
|
|
|
ActiveForums 3.7
|