You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Gary Hinger <Ga...@wildtangent.com> on 2006/07/01 02:41:27 UTC

XML configuration file - extracting elements

Is there a way to extract elements from log4net's XML configuration
file, without reopening the file and parsing it?

 

For example, I'd like to get a certain appender's "file" property, so
that I can create the logging directory every time logging is done. I
need to do this to support runtime changes in the directory
specification in config xml. Since the log4net assembly is designed to
watch the file, it would be a shame to have to reparse the file in
separate code.

 

Also, is there a way to get log4net to create directories as necessary
when logging? This would solve my immediate problem. Thanks.

 


Re: XML configuration file - extracting elements

Posted by Ron Grabowski <ro...@yahoo.com>.
You can get a list of appenders by calling GetAppenders:

 IAppender[] appenders = LogManager.GetRepository().GetAppenders();

If you need to modifiy an appender at run-time, you should be able to
find the appender using the above code, modify the appender, then call
ActivateOptions to re-initialize it.

The FileAppender automatically creates the directory structure if it
does not exist (lines 400 and 533 of FileAppender.cs are calls to
Directory.CreateDirectory(string)).

--- Gary Hinger <Ga...@wildtangent.com> wrote:

> Is there a way to extract elements from log4net's XML configuration
> file, without reopening the file and parsing it?
> 
>  
> 
> For example, I'd like to get a certain appender's "file" property, so
> that I can create the logging directory every time logging is done. I
> need to do this to support runtime changes in the directory
> specification in config xml. Since the log4net assembly is designed
> to
> watch the file, it would be a shame to have to reparse the file in
> separate code.
> 
>  
> 
> Also, is there a way to get log4net to create directories as
> necessary
> when logging? This would solve my immediate problem. Thanks.
> 
>  
> 
>