I have made for this purpose configuration program which modifies
.log4net.config and replaces paths for all appenders.
Remember, config is normal XML document, so you can modify it through
DOM model.

Here is code snippet which does it. Do not compile, but for inspiration:

public void UpdateAppenderFileDirs(string dirName)
{
   System.Xml.XmlNodeList xmlNList;
   xmlNList =
_configXmlDoc.DocumentElement.SelectNodes("/configuration/log4net/appender/file");
   foreach (System.Xml.XmlNode node in xmlNList)
    {
        XmlNode attr = node.Attributes.GetNamedItem("value");
        if (attr == null)
        {
           throw (ExcUtils.XmlAttributeNotFound("value", node));
        }
        attr.InnerXml = Path.Combine(dirName, Path.GetFileName(attr.InnerXml));
        }
}

---------
Prostredi: C#, VS2005 Pro, XP Pro/P4 3GHz, 2GB RAM
___________________________________________________
Karel Kral, senior developer
ANETE, s.r.o.
___________________________________________________

Dne 26.11.2007 8:48, Chan Kong Hing napsal(a):
> I am a newbie in .Net C# and log4Net.
>  
> I have my log4net running OK with my .NET app and this is the
> configuration file.
>  
> I need to display to end-user what the directory is for my log file and
> i want to allow user to provide a new directory name to update the log file.
>  
> how i can do that?
>  
> please help and thanks
>  
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <configSections>
> <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
> </configSections>
> <log4net>
> <appender name="LogFileAppender"
> type="log4net.Appender.RollingFileAppender">
> <file value="c:\\app.log" />
> <appendToFile value="true" />
> <rollingStyle value="Size" />
> <maxSizeRollBackups value="10" />
> <maximumFileSize value="1024KB" />
> <staticLogFileName value="true" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%thread] %-5level %logger -
> %message%newline" />
> </layout>
> </appender>
> <root>
> <level value="ALL" />
> <appender-ref ref="LogFileAppender" />
> </root>
> </log4net>
> 
> ------------------------------------------------------------------------
> Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try
> it now.
> <http://us.rd.yahoo.com/evt=51731/*http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
>>

Reply via email to