The config file parser will look for a property or method on the target
object. For example if the property is specified in the config file as:

<file value="log.txt" />

Then the parser will look for a settable property called 'file', the
match is done case-insensitively. If no property can be found it will
look for a method called 'addfile' (again case-insensitively). Once it
has found the property or method it will try to convert the value, in
this case a string, into the correct type for the property.

For certain properties the value can be retrieved via reflection. Where
an 'Add' method is used to build up a collection there may be no
discoverable way of finding the configuration values.

Type conversion takes place at configuration time, this means that some
of the information in the config file is not passed through to the
appender objects. For example a 'pattern string' can be used to
customise the value of a property:

<file type="log4net.Util.PatternString" value="log[%processid].txt" />

The file property is set to "log[1234].txt" (or whatever the process id
is), this configuration is not possible to recover from the configured
objects.

In order to modify an existing configuration it may be best to load the
config file into an XML document, modify it, and then save it again
rather than trying to reflect the sate of the loggers and appenders.

Nicko

> -----Original Message-----
> From: Richard Louapre [mailto:[EMAIL PROTECTED] 
> Sent: 31 March 2005 18:00
> To: 'Log4NET User'
> Subject: RE: Programmatically update the config file.
> 
> Thanks for your answer.
> 
> <log4net>
>       <appender name="Console" 
> type="log4net.Appender.ConsoleAppender">
>               <layout type="log4net.Layout.PatternLayout">
>                       <!-- Pattern to output the caller's 
> file name and line number -->
>                       <conversionPattern value="%5level [%thread]
> (%file:%line) - %message %newline" />
>               </layout>
>       </appender>
>       <root>
>               <level value="DEBUG"/>
>               <appender-ref ref="Console" />
>       </root>
> </log4net>
> 
> So if I understand correctly, I will need to generate 
> "manually" an XmlDocument for this log4net settings above. 
> There is no way to serialize the Hierarchy object and get in 
> output this XmlDocument?
> If there is no way, is there an exact matching between the 
> property name and associated node in the config file? That 
> could help me a lot using Reflection.
> 
> Thanks again.
> 
> Ciao,
>       Richard.
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 31, 2005 11:50 AM
> To: Log4NET User
> Subject: Re: Programmatically update the config file.
> 
> 
> The config file is just a standard XML file. Have you tried using an
> XmlDocument object to read the file in, make your changes, 
> then write it
> back to the file system? If you've configured log4net to 
> place a file system
> watch on the file, when you save the file back out to the 
> hard drive log4net
> will re-process it and the changes will take affect.
> 
> 
> - Ron
> 
> --- Richard Louapre <[EMAIL PROTECTED]> wrote:
> > Hi,
> > 
> > I need to programmatically update the config file 
> (log4net.config) in 
> > order to keep the changes apply to my log system.
> > I did not find anything to do that, maybe I have missed something.
> > 
> > Does anybody have an sample?
> > 
> > Many Thanks.
> > 
> > Ciao,
> >     Richard.
> > 
> 

Reply via email to