logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vanderkolk, John" <John.Vanderk...@compuware.com>
Subject RE: Disable/enable appender for all loggers
Date Fri, 27 Jul 2007 12:26:32 GMT
I would do something like this:


      log4net.Appender.IAppender[] appenders =


      for (int i = 0; i < appenders.Length; ++i)


            Log4net.Appender.FileAppender appender = appenders[i] as

            if (appender != null && appender.Name == "RollingFile")

                  appender.Threshold = log4net.Core.Level.Off;



Or if you want to turn all File Appenders you can take out the ' &&
appender.Name == "RollingFile"'.


John VanderKolk 

From: Radovan Raszka [mailto:raszka@hasam.cz] 
Sent: Friday, July 27, 2007 2:23 AM
To: log4net-user@logging.apache.org
Subject: Disable/enable appender for all loggers


I am using three appenders in my log4net configuration (see bellow). But
I need programatically disable and reenable RollingFile appender at
certain situations. Is there any simple solution? I tried to use
programatic configuration only.

My config: 
                <appender name="Console"
                        <layout type="log4net.Layout.PatternLayout"> 
                                <!-- Pattern to output the caller's file
name and line number --> 
value="%date{HH:mm:ss,fff} %5level [%thread] %message%n" /> 
                        <Threshold value="DEBUG" /> 

                <appender name="RollingFile"
                        <appendToFile value="true" /> 
                        <file value="Service.log" /> 
                        <layout type="log4net.Layout.PatternLayout"> 
value="%date{dd-MM-yyyy HH:mm:ss,fff} %5level [%2thread] %message
(%logger{1}:%line)%n" />

                        <rollingStyle value="Date" /> 
                        <Threshold value="DEBUG" /> 

                <appender name="EvLog"
                        <ApplicationName value="IPserver" /> 
                        <layout type="log4net.Layout.PatternLayout"> 
                                <conversionPattern value="[%thread]
%message (%logger{1})" /> 
                        <Threshold value="INFO" /> 

                        <level value="DEBUG" /> 
                        <appender-ref ref="RollingFile" /> 
                        <appender-ref ref="Console" /> 
                        <appender-ref ref="EvLog" /> 

I tried to complete rewrite this config into C# code: 

private readonly log4net.Appender.ConsoleAppender AppConsole; 
private readonly log4net.Appender.RollingFileAppender AppFile; 
private readonly log4net.Appender.EventLogAppender AppEvlog; 
private log4net.Repository.Hierarchy.RootLogger rootLog; 
System.IO.FileInfo(IPserverCore.IPserver.GetAppPath() +
//xml configurator replaced by code 
AppConsole = new log4net.Appender.ConsoleAppender(); 
AppConsole.Layout = new
log4net.Layout.PatternLayout("%date{HH:mm:ss,fff} %5level [%thread]
AppConsole.Threshold = log4net.Core.Level.Debug; 

AppFile = new log4net.Appender.RollingFileAppender(); 
AppFile.AppendToFile = true; 
AppFile.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy
HH:mm:ss,fff} %5level [%2thread] %message (%logger{1}:%line)%n");

AppFile.File = "Service.log"; 
AppFile.RollingStyle =
AppFile.Threshold = log4net.Core.Level.Debug; 

AppEvlog = new log4net.Appender.EventLogAppender(); 
AppEvlog.Layout = new log4net.Layout.PatternLayout("[%thread] %message
AppEvlog.ApplicationName = "IPserver"; 
AppEvlog.Threshold = log4net.Core.Level.Info; 

rootLog = new
log = LogManager.GetLogger(typeof(IPservice)); 
Log.Info("Start"); // no log produced here... 
rootLog.RemoveAppender(AppFile); // disable file logging 
But after rewriting aplication doesn't create any logs.... 
Did I miss some settings or am I complete wrong? 

Thanks for any suggestions 
Radovan Raszka
The contents of this e-mail are intended for the named addressee only. It contains information
that may be confidential. Unless you are the named addressee or an authorized designee, you
may not copy or use it, or disclose it to anyone else. If you received it in error please
notify us immediately and then destroy it.

View raw message