logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: File logging
Date Thu, 21 Jul 2005 18:32:31 GMT
In log4net 1.2.9 beta you can do the following to set the File property
on a configured appender:

foreach(log4net.Appender.IAppender appender in
log4net.LogManager.GetRepository().GetAppenders())
{
  if (appender is log4net.Appender.FileAppender)
  {
    ((log4net.Appender.FileAppender)appender).File = "path";
    ((log4net.Appender.FileAppender)appender).ActivateOptions();
  }
}

If you have more than 1 FileAppender you may want to check the appenders
Name property.

If you are using an older version of log4net without the GetAppenders
method you will need to do this manually:

public static log4net.Appender.IAppender[] GetAppenders()
{
  ArrayList appenders = new ArrayList();

 
appenders.AddRange(((log4net.Repository.Hierarchy.Hierarchy)log4net.LogM
anager.GetLoggerRepository()).Root.Appenders);
  foreach(log4net.ILog log in log4net.LogManager.GetCurrentLoggers())
  {
 
appenders.AddRange(((log4net.Repository.Hierarchy.Logger)log.Logger).App
enders);
  }

  return
(log4net.Appender.IAppender[])appenders.ToArray(typeof(log4net.Appender.
IAppender));
}

Nicko

> -----Original Message-----
> From: Senthil Sivasubramanian 
> [mailto:Senthil.Sivasubramanian@headstrong.com] 
> Sent: 21 July 2005 09:38
> To: Log4NET Dev
> Cc: log4net-user@logging.apache.org
> Subject: File logging
> 
> I am using DOM configurator for configuring log4net settings 
> from a config file in my application. I use File Appender for 
> recording the logs in a file.
> 
>  
> 
> Is it possible for programmatically changing the file name 
> sometime after the application is started?
> 
>  
> 
> Specifically, I want to know how can I programmatically set 
> the File property of the File Appender.
> 
>  
> 
> Thank you.
> 
> *************The information transmitted is intended only for 
> the person or entity to which it is addressed and may contain 
> confidential and/or privileged material. Any 
> review,retransmission,dissemination or other use of, or 
> taking of any action in reliance upon, this information by 
> persons or entities other than the intended recipient is 
> prohibited. If you received this in error, please contact the 
> sender and delete the material from any computer.*********************
> 
> 

Mime
View raw message