Change the logging directory at runtime

Hi,

I'm planning to use log4net to write events in a removable usb memory.

As you can suppose I have problems setting the right path for the logging file in the removable drive, there is no warranty about the drive where the memory will be mounted each time; and the application, depending on its state, it can be using different removable memories at different times.

I wonder if there is any way of setting the file path of the FileAppender or RollingFileAppender at runtime.

Thanks in advance,

Freddy.
Rennie Petersen | 29 Jul 21:26

RE: Change the logging directory at runtime

This may not be the best method, but it is possible to modify the log4net.config.xml file at runtime.
 
This requires that you have used the ConfigureAndWatch method of configuring log4net.
 
Rennie
 

From: Freddy Gómez [mailto:gcfreddy <at> gmail.com]
Sent: 29. juli 2008 20:59
To: log4net-user <at> logging.apache.org
Subject: Change the logging directory at runtime

Hi,

I'm planning to use log4net to write events in a removable usb memory.

As you can suppose I have problems setting the right path for the logging file in the removable drive, there is no warranty about the drive where the memory will be mounted each time; and the application, depending on its state, it can be using different removable memories at different times.

I wonder if there is any way of setting the file path of the FileAppender or RollingFileAppender at runtime.

Thanks in advance,

Freddy.

Re: Change the logging directory at runtime

Thanks Rennie, your solution will get in the list of options.

Fred.

On Tue, Jul 29, 2008 at 2:56 PM, Rennie Petersen <rp <at> merlinia.com> wrote:
This may not be the best method, but it is possible to modify the log4net.config.xml file at runtime.
 
This requires that you have used the ConfigureAndWatch method of configuring log4net.
 
Rennie
 

From: Freddy Gómez [mailto:gcfreddy <at> gmail.com]
Sent: 29. juli 2008 20:59
To: log4net-user <at> logging.apache.org
Subject: Change the logging directory at runtime

Hi,

I'm planning to use log4net to write events in a removable usb memory.

As you can suppose I have problems setting the right path for the logging file in the removable drive, there is no warranty about the drive where the memory will be mounted each time; and the application, depending on its state, it can be using different removable memories at different times.

I wonder if there is any way of setting the file path of the FileAppender or RollingFileAppender at runtime.

Thanks in advance,

Freddy.

Josh Kewley | 31 Jul 19:08

RE: Change the logging directory at runtime

I wrote a post on this a long time ago:

http://insario.com/blog/jfk/archive/2004/11/30/164.aspx

it’s dated, but you may be able to use it as a starting point.

-Josh

 

From: Freddy Gómez [mailto:gcfreddy <at> gmail.com]
Sent: Tuesday, July 29, 2008 11:59 AM
To: log4net-user <at> logging.apache.org
Subject: Change the logging directory at runtime

 

Hi,

I'm planning to use log4net to write events in a removable usb memory.

As you can suppose I have problems setting the right path for the logging file in the removable drive, there is no warranty about the drive where the memory will be mounted each time; and the application, depending on its state, it can be using different removable memories at different times.

I wonder if there is any way of setting the file path of the FileAppender or RollingFileAppender at runtime.

Thanks in advance,

Freddy.

Re: Change the logging directory at runtime

Thanks Josh, that's the kind of solution I'm looking for.

However I need to go a step beyond because I need several appenders logging in several directories (all of them set at runtime).

What I gonna do is to create an appender (subclassing RollingFileApplender) with a parameter which will be a class who implement a property 'LogDirectory' (As your 'Web.WebEnvironment.LogDirectory') and then create a class who return its own directory to each appender. If I do it well all the configuration needed will be placed in the configuration file.

I'll post again If I have success.

-Fred

On Thu, Jul 31, 2008 at 12:38 PM, Josh Kewley <jkewley <at> insario.com> wrote:

I wrote a post on this a long time ago:

http://insario.com/blog/jfk/archive/2004/11/30/164.aspx

it's dated, but you may be able to use it as a starting point.

-Josh

 

From: Freddy Gómez [mailto:gcfreddy <at> gmail.com]
Sent: Tuesday, July 29, 2008 11:59 AM


To: log4net-user <at> logging.apache.org
Subject: Change the logging directory at runtime

 

Hi,



I'm planning to use log4net to write events in a removable usb memory.

As you can suppose I have problems setting the right path for the logging file in the removable drive, there is no warranty about the drive where the memory will be mounted each time; and the application, depending on its state, it can be using different removable memories at different times.

I wonder if there is any way of setting the file path of the FileAppender or RollingFileAppender at runtime.

Thanks in advance,

Freddy.


Gmane