The config file parser supports expanding environment variables. You
need to use the following syntax:

${USERPROFILE} 

Also with the current CVS version you can use a PatternString converter
to do the same this:

%env{USERPROFILE}

Cheers,
Nicko


> -----Original Message-----
> From: Mike [mailto:[EMAIL PROTECTED] 
> Sent: 08 December 2004 02:22
> To: [email protected]
> Subject: Using Environment variables in the FileAppender.File 
> property.
> 
> Hi All,
> 
> I've been using log4net on an xp platform, and I wanted each 
> users log file to go into their separate user folders.  To 
> achieve this, I've changed the FileAppender.ConvertToFullPath 
> method as follows.
> 
> protected static string ConvertToFullPath(string path) {
>       if (path == null)
>       {
>               throw new ArgumentNullException("path");
>       }
> 
>       string expandedPath = 
> Environment.ExpandEnvironmentVariables(path);
> 
>       if (SystemInfo.ApplicationBaseDirectory != null)
>       {
>               // Note that Path.Combine will return the 
> second path if it is rooted
>               return Path.GetFullPath(
>                       
> Path.Combine(SystemInfo.ApplicationBaseDirectory, expandedPath));
>       }
>       return Path.GetFullPath(expandedPath);
> }
> 
> Pretty much the same as how it was, just expanded the env 
> variables between getting the full path.  This way the file 
> '%USERPROFILE%\mylog.txt' will go into the user folder.  Is 
> this something that would be useful for others, or is this 
> functionality already present somewhere, and I've overlooked it?
> 
> Cheers -Mike
> 
> "The pure and simple truth is rarely pure and never simple."
> Oscar Wilde
> 
> 

Reply via email to