Yes, it is possible to configure logging programatically. It was discussed
here, see the archive:
http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200805.mbox/%[email protected]%3e
How to get appenders (this example adds or removes file appender):
private static void enableDebugLog(bool enable)
{
RollingFileAppender rfa = null;
log4net.Repository.Hierarchy.Logger root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
foreach (AppenderSkeleton appender in
LogManager.GetRepository().GetAppenders())
{
rfa = appender as RollingFileAppender;
if (rfa != null) //file appender found!
break;
}
if (enable)
{
if (rfa != null) return; // already exists, no need to add
RollingFileAppender debugLog = new RollingFileAppender();
debugLog.AppendToFile = true;
debugLog.File = "Log/Service.log";
debugLog.Layout = new
log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level [%2thread]
%message (%logger{1}:%line)%n");
debugLog.RollingStyle = RollingFileAppender.RollingMode.Date;
debugLog.Threshold = log4net.Core.Level.Debug;
debugLog.ActivateOptions();
root.AddAppender(debugLog);
}
else
{
if (rfa == null) return; // already doesn't exist, no need to
delete
root.RemoveAppender(rfa);
rfa.Close();
}
}
I think new log entries can not be added to the top of file.
Radovan Raszka
-----Původní zpráva-----
Od: xalex [mailto:[email protected]]
Odesláno: 23. července 2009 17:44
Komu: [email protected]
Předmět: Re: Wrapping Log4Net
Hi,
i did not find it in the documentation:
Is it possible to configure appenders by coding without configfiles?
How do i get the appenders which are currently configured? I would like to
change the output destination file of a FileAppender.
And last question: is it possible to configure a FileAppender so that the
newest log entry is at top of the file and not at the bottom?
Thank you in advance!
Alex
--
View this message in context:
http://www.nabble.com/Wrapping-Log4Net-tp24551728p24628718.html
Sent from the Log4net - Users mailing list archive at Nabble.com.