Ron,
The file path is relative. It is relative to the value of:
AppDomain.CurrentDomain.BaseDirectory
In ASP.NET I think this is set to the windows system32 directory. Which
is not very helpful.
In log4net 1.2 beta 8 it is not possible to parameterise the File path
directly. It is possible to extend the FileAppender and override the
File property to add support for the ASP.NET "~" syntax.
If you are using the CVS version of log4net you can also do this by
using a PatternString to set the File property.
For example if you wanted to write the file to a user's special folder,
e.g. their "MyMusic" folder you can use a PatternString with a custom
pattern converter:
<file type="log4net.Util.PatternString">
<converter>
<name value="folder" />
<type
value="TestConsoleApp.SpecialFolderPatternConverter,TestConsoleApp" />
</converter>
<conversionPattern value="%folder{MyMusic}\log-file.txt" />
</file>
The code for the %folder pattern can then be implemented as:
public class SpecialFolderPatternConverter :
log4net.Util.PatternConverter
{
override protected void Convert(System.IO.TextWriter writer, object
state)
{
Environment.SpecialFolder specialFolder =
(Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder),
base.Option, true);
writer.Write(Environment.GetFolderPath(specialFolder));
}
}
This could be simplified to just return
System.Web.HttpRuntime.AppDomainAppPath instead.
Cheers,
Nicko
> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED]
> Sent: 24 November 2004 15:39
> To: [email protected]
> Subject: Ability to use tilda (or relative path) when
> specifing output file in config file for ASP.Net logging
>
> On my dev machine, I have several appenders that write to various log
> files:
>
> <param name="File"
> value="C:\\Inetpub\\wwwroot\\testsite\\Data\\Logs\\log.txt" />
>
> When I move this to a different server, the file path won't
> always be C:\inetpub\wwwroot\testsite... Is there a way I can
> use a relative path on the param tag or on the log4net tag?
>
> <param name="File" value="~/Data/Logs/log.txt" />
>
> <log4net debug="true" BasePath="d:\\inetpub\\">
>
> Its a pain having to make sure all the paths are correct
> (especially for long config files). Depending on the
> deployment environment, I may not know the true physical path
> unless I do some digging around.
>
> I saw that Configure() has an overload that accepts a
> System.IO.Stream and/or XmlElement. I suppose I could load
> the file from disk, change the file paths dynmically, then
> send the config information to Configure(). Is there a better way?
>
> - Ron
>