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 Christian Chenier <cc...@uottawa.ca> on 2009/08/05 18:15:57 UTC

relative path for config file

Hi,

I use log4net in a C# web application and am having problems configuring
it to use a relative path to point to the location of a configuration
file external to web.config.

 

In web.config, if I use

      <add key="log4net.Config.File" value="C:\somePath\log4net.config"
/>

all works fine. However, I would like to avoid having to hard-code the
physical path and would like to specify something like

      <add key="log4net.Config.File" value="configs\log4net.config" />

where the configs directory is located in the same directory as
web.config (the AppDomain.CurrentDomain.BaseDirectory). However this
does not work (I no longer get anything output to my log file when I
make that change).

 

I understand that one can programmatically construct a full path from
the base directory, but there is surely a way to specify a relative path
directly in the web.config file? I have tried modifying the string using
leading slash (and backslash), etc. to no avail, and could not find a
solution anywhere. Does anyone know how to do this?

 

(As an aside, using a relative path to specify the output file name
within the <appender> works fine, relative to the base directory.)

 

Thanks,

 

Chris Chenier

 


Re: relative path for config file

Posted by Michael Schall <mi...@gmail.com>.
We configure our logging in code using an external xml file using
log4net.Config.XmlConfigurator.ConfigureAndWatch.

This way  I can change my logging settings without resetting my website.

Mike

2009/8/6 Karim Bourouba <ka...@hotmail.com>:
>
> Hi There,
>
>
>
> I understand you desire to have a central directory for log files - but
> surely if they are all going to live in the \Configs dir, then this
> directory will always be in the same place on each machine?
>
>
>
> Other than that, I think unless you want to have a seperate utility to
> manage your logfiles for you, then you will probably need to set the path in
> the code :(
>
>
>
> Raszka - sometimes it is very useful to hold some configuration in an
> external xml file.
>
>
>
> ________________________________
> Subject: RE: relative path for config file
> Date: Thu, 6 Aug 2009 08:14:47 +0200
> From: raszka@hasam.cz
> To: log4net-user@logging.apache.org
>
> Hi,
> you can try this:
> <add key="log4net.Config.File" value="~\configs\log4net.config" />
> but I'm not sure if this works. What you are using external config
> file? log4net config can be written directly in web.config.
> RR
> ________________________________
> Od: Christian Chenier [mailto:cchenier@uottawa.ca]
> Odesláno: 5. srpna 2009 18:16
> Komu: log4net-user@logging.apache.org
> Předmět: relative path for config file
>
> Hi,
>
> I use log4net in a C# web application and am having problems configuring it
> to use a relative path to point to the location of a configuration file
> external to web.config.
>
>
>
> In web.config, if I use
>
>       <add key="log4net.Config.File" value="C:\somePath\log4net.config" />
>
> all works fine. However, I would like to avoid having to hard-code the
> physical path and would like to specify something like
>
>       <add key="log4net.Config.File" value="configs\log4net.config" />
>
> where the configs directory is located in the same directory as web.config
> (the AppDomain.CurrentDomain.BaseDirectory). However this does not work (I
> no longer get anything output to my log file when I make that change).
>
>
>
> I understand that one can programmatically construct a full path from the
> base directory, but there is surely a way to specify a relative path
> directly in the web.config file? I have tried modifying the string using
> leading slash (and backslash), etc. to no avail, and could not find a
> solution anywhere. Does anyone know how to do this?
>
>
>
> (As an aside, using a relative path to specify the output file name within
> the <appender> works fine, relative to the base directory.)
>
>
>
> Thanks,
>
>
>
> Chris Chenier
>
>
>
> ________________________________
> Windows Live Messenger: Happy 10-Year Anniversary-get free winks and
> emoticons. Get Them Now

RE: relative path for config file

Posted by Karim Bourouba <ka...@hotmail.com>.

Hi There,
 
I understand you desire to have a central directory for log files - but surely if they are all going to live in the \Configs dir, then this directory will always be in the same place on each machine?
 
Other than that, I think unless you want to have a seperate utility to manage your logfiles for you, then you will probably need to set the path in the code :(
 
Raszka - sometimes it is very useful to hold some configuration in an external xml file. 

 



Subject: RE: relative path for config file
Date: Thu, 6 Aug 2009 08:14:47 +0200
From: raszka@hasam.cz
To: log4net-user@logging.apache.org




Hi,
you can try this:
<add key="log4net.Config.File" value="~\configs\log4net.config" />
but I'm not sure if this works. What you are using external config file? log4net config can be written directly in web.config.
RR



Od: Christian Chenier [mailto:cchenier@uottawa.ca] 
Odesláno: 5. srpna 2009 18:16
Komu: log4net-user@logging.apache.org
Předmět: relative path for config file




Hi,
I use log4net in a C# web application and am having problems configuring it to use a relative path to point to the location of a configuration file external to web.config.
 
In web.config, if I use
      <add key="log4net.Config.File" value="C:\somePath\log4net.config" />
all works fine. However, I would like to avoid having to hard-code the physical path and would like to specify something like
      <add key="log4net.Config.File" value="configs\log4net.config" />
where the configs directory is located in the same directory as web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does not work (I no longer get anything output to my log file when I make that change).
 
I understand that one can programmatically construct a full path from the base directory, but there is surely a way to specify a relative path directly in the web.config file? I have tried modifying the string using leading slash (and backslash), etc. to no avail, and could not find a solution anywhere. Does anyone know how to do this?
 
(As an aside, using a relative path to specify the output file name within the <appender> works fine, relative to the base directory.)
 
Thanks,
 

Chris Chenier
 
_________________________________________________________________
Windows Live Messenger: Happy 10-Year Anniversary-get free winks and emoticons.
http://clk.atdmt.com/UKM/go/157562755/direct/01/

Re: relative path for config file

Posted by Ross Hinkley <ro...@gmail.com>.
Christian,

I'm pretty certain you can specify log4net configurations per assembly using
something like the following in your AssemblyInfo.cs:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "ConfigFile.config",
Watch = true)]

I don't know if that helps you.

I guess I'm not seeing how your config setting is mapping to the
configuration path.  I feel like I'm still missing a piece of the puzzle.

-Ross

2009/8/7 Christian Chenier <cc...@uottawa.ca>

>  I tried using
>
> <add key="log4net.Config.File" value="~\configs\log4net.config" />
>
> but unfortunately this does not work.
>
>
>
> I am setting the configuration file path in web.config under
> <configuration><appSettings>
>
>
>
> As stated, this works fine if I specify a full path for the configuration
> file, but I have not yet found any working syntax to specify a relative
> path.
>
>
>
> Thanks to those who have provided feedback.
>
>
>
> Chris Chenier
>
> Service de l'informatique et des communications | Computing and
> Communications Services
> 613-562-5800 x1675
> cchenier@uottawa.ca
>   ------------------------------
>
> *From:* Ross Hinkley [mailto:rosshinkley@gmail.com]
> *Sent:* August 6, 2009 11:40 AM
> *To:* Log4NET User
> *Subject:* Re: relative path for config file
>
>
>
> Christian,
>
> Out of curiosity, how and where are you setting the configuration file
> path?
>
> -Ross
>
> 2009/8/6 thierry lach <th...@hotmail.com>
>
> One good reason for using an external file would be that the file can be
> changed without restarting the web application, which would happen when
> updating web.config.
>
>
>
>
>   *[image: i'm]EMAILING FOR THE GREATER GOOD
> Join me<http://im.live.com/Messenger/IM/Home/?source=EML_WLHM_GreaterGood>
> *
>
>
>  ------------------------------
>
> Subject: RE: relative path for config file
> Date: Thu, 6 Aug 2009 08:14:47 +0200
> From: raszka@hasam.cz
>
> To: log4net-user@logging.apache.org
>
>
>
> Hi,
>
> you can try this:
>
> <add key="log4net.Config.File" value="~\configs\log4net.config" />
>
> but I'm not sure if this works. What you are using external config
> file? log4net config can be written directly in web.config.
>
> RR
>
>
>  ------------------------------
>
> *Od:* Christian Chenier [mailto:cchenier@uottawa.ca]
> *Odesláno:* 5. srpna 2009 18:16
> *Komu:* log4net-user@logging.apache.org
> *Předmět:* relative path for config file
>
> Hi,
>
> I use log4net in a C# web application and am having problems configuring
> it to use a relative path to point to the location of a configuration file
> external to web.config.
>
>
>
> In web.config, if I use
>
>       <add key="log4net.Config.File" value="C:\somePath\log4net.config" />
>
> all works fine. However, I would like to avoid having to hard-code the
> physical path and would like to specify something like
>
>       <add key="log4net.Config.File" value="configs\log4net.config" />
>
> where the *configs* directory is located in the same directory as
> web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does
> not work (I no longer get anything output to my log file when I make that
> change).
>
>
>
> I understand that one can programmatically construct a full path from the
> base directory, but there is surely a way to specify a relative path
> directly in the web.config file? I have tried modifying the string using
> leading slash (and backslash), etc. to no avail, and could not find a
> solution anywhere. Does anyone know how to do this?
>
>
>
> (As an aside, using a relative path to specify the output file name within
> the <appender> works fine, relative to the base directory.)
>
>
>
> Thanks,
>
>
>
> Chris Chenier
>
>
>
>
>

RE: relative path for config file

Posted by Christian Chenier <cc...@uottawa.ca>.
I tried using

<add key="log4net.Config.File" value="~\configs\log4net.config" />

but unfortunately this does not work.

 

I am setting the configuration file path in web.config under <configuration><appSettings>

 

As stated, this works fine if I specify a full path for the configuration file, but I have not yet found any working syntax to specify a relative path.

 

Thanks to those who have provided feedback.

 

Chris Chenier

Service de l'informatique et des communications | Computing and Communications Services
613-562-5800 x1675
cchenier@uottawa.ca <ma...@uottawa.ca>  

________________________________

From: Ross Hinkley [mailto:rosshinkley@gmail.com] 
Sent: August 6, 2009 11:40 AM
To: Log4NET User
Subject: Re: relative path for config file

 

Christian,

Out of curiosity, how and where are you setting the configuration file path?

-Ross

2009/8/6 thierry lach <th...@hotmail.com>

One good reason for using an external file would be that the file can be changed without restarting the web application, which would happen when updating web.config.






i'mEMAILING FOR THE GREATER GOOD
Join me <http://im.live.com/Messenger/IM/Home/?source=EML_WLHM_GreaterGood> 

 

________________________________

Subject: RE: relative path for config file
Date: Thu, 6 Aug 2009 08:14:47 +0200
From: raszka@hasam.cz

To: log4net-user@logging.apache.org

 

Hi,

you can try this:

<add key="log4net.Config.File" value="~\configs\log4net.config" />

but I'm not sure if this works. What you are using external config file? log4net config can be written directly in web.config.

RR

 

________________________________

Od: Christian Chenier [mailto:cchenier@uottawa.ca] 
Odesláno: 5. srpna 2009 18:16
Komu: log4net-user@logging.apache.org
Předmět: relative path for config file

Hi,

I use log4net in a C# web application and am having problems configuring it to use a relative path to point to the location of a configuration file external to web.config.

 

In web.config, if I use

      <add key="log4net.Config.File" value="C:\somePath\log4net.config" />

all works fine. However, I would like to avoid having to hard-code the physical path and would like to specify something like

      <add key="log4net.Config.File" value="configs\log4net.config" />

where the configs directory is located in the same directory as web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does not work (I no longer get anything output to my log file when I make that change).

 

I understand that one can programmatically construct a full path from the base directory, but there is surely a way to specify a relative path directly in the web.config file? I have tried modifying the string using leading slash (and backslash), etc. to no avail, and could not find a solution anywhere. Does anyone know how to do this?

 

(As an aside, using a relative path to specify the output file name within the <appender> works fine, relative to the base directory.)

 

Thanks,

 

Chris Chenier

 

 


Re: relative path for config file

Posted by Ross Hinkley <ro...@gmail.com>.
Christian,

Out of curiosity, how and where are you setting the configuration file path?

-Ross

2009/8/6 thierry lach <th...@hotmail.com>

>  One good reason for using an external file would be that the file can be
> changed without restarting the web application, which would happen when
> updating web.config.
>
>
>
>
>
> [image: i'm] EMAILING FOR THE GREATER GOOD
> Join me<http://im.live.com/Messenger/IM/Home/?source=EML_WLHM_GreaterGood>
>
> ------------------------------
> Subject: RE: relative path for config file
> Date: Thu, 6 Aug 2009 08:14:47 +0200
> From: raszka@hasam.cz
> To: log4net-user@logging.apache.org
>
>
> Hi,
> you can try this:
> <add key="log4net.Config.File" value="~\configs\log4net.config" />
> but I'm not sure if this works. What you are using external config
> file? log4net config can be written directly in web.config.
> RR
>
>  ------------------------------
> *Od:* Christian Chenier [mailto:cchenier@uottawa.ca]
> *Odesláno:* 5. srpna 2009 18:16
> *Komu:* log4net-user@logging.apache.org
> *Předmět:* relative path for config file
>
>  Hi,
>
> I use log4net in a C# web application and am having problems configuring
> it to use a relative path to point to the location of a configuration file
> external to web.config.
>
>
>
> In web.config, if I use
>
>       <add key="log4net.Config.File" value="C:\somePath\log4net.config" />
>
> all works fine. However, I would like to avoid having to hard-code the
> physical path and would like to specify something like
>
>       <add key="log4net.Config.File" value="configs\log4net.config" />
>
> where the *configs* directory is located in the same directory as
> web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does
> not work (I no longer get anything output to my log file when I make that
> change).
>
>
>
> I understand that one can programmatically construct a full path from the
> base directory, but there is surely a way to specify a relative path
> directly in the web.config file? I have tried modifying the string using
> leading slash (and backslash), etc. to no avail, and could not find a
> solution anywhere. Does anyone know how to do this?
>
>
>
> (As an aside, using a relative path to specify the output file name within
> the <appender> works fine, relative to the base directory.)
>
>
>
> Thanks,
>
>
>
> Chris Chenier
>
>
>

RE: relative path for config file

Posted by thierry lach <th...@hotmail.com>.
One good reason for using an external file would be that the file can be changed without restarting the web application, which would happen when updating web.config.





 EMAILING FOR THE GREATER GOOD
Join me

Subject: RE: relative path for config file
Date: Thu, 6 Aug 2009 08:14:47 +0200
From: raszka@hasam.cz
To: log4net-user@logging.apache.org










Hi,
you can try this:
<add 
key="log4net.Config.File" value="~\configs\log4net.config" 
/>
but I'm not sure if this works. What you 
are using external config file? log4net config can be written directly in 
web.config.
RR



Od: Christian Chenier 
[mailto:cchenier@uottawa.ca] 
Odesláno: 5. srpna 2009 
18:16
Komu: log4net-user@logging.apache.org
Předmět: 
relative path for config file




Hi,
I use log4net in a 
C# web application and am having 
problems configuring it to use a relative path to point to the location of a 
configuration file external to web.config.
 
In web.config, if I 
use
      
<add 
key="log4net.Config.File" value="C:\somePath\log4net.config" 
/>
all works fine. However, I would 
like to avoid having to hard-code the physical path and would like to specify 
something like
      
<add 
key="log4net.Config.File" value="configs\log4net.config" />
where the configs directory is located in the same 
directory as web.config (the AppDomain.CurrentDomain.BaseDirectory). However 
this does not work (I no longer get anything output to my log file when I make 
that change).
 
I understand that one can 
programmatically construct a full path from the base directory, but there is 
surely a way to specify a relative path directly in the web.config file? I have 
tried modifying the string using leading slash (and backslash), etc. to no 
avail, and could not find a solution anywhere. Does anyone know how to do 
this?
 
(As an aside, using a relative path 
to specify the output file name within the <appender> works fine, relative 
to the base directory.)
 
Thanks,
 

Chris Chenier
 

RE: relative path for config file

Posted by Radovan Raszka <ra...@hasam.cz>.
Hi,
you can try this:
<add key="log4net.Config.File" value="~\configs\log4net.config" />
but I'm not sure if this works. What you are using external config file? log4net config can be written directly in web.config.
RR


________________________________

Od: Christian Chenier [mailto:cchenier@uottawa.ca] 
Odesláno: 5. srpna 2009 18:16
Komu: log4net-user@logging.apache.org
Předmět: relative path for config file



Hi,

I use log4net in a C# web application and am having problems configuring it to use a relative path to point to the location of a configuration file external to web.config.

 

In web.config, if I use

      <add key="log4net.Config.File" value="C:\somePath\log4net.config" />

all works fine. However, I would like to avoid having to hard-code the physical path and would like to specify something like

      <add key="log4net.Config.File" value="configs\log4net.config" />

where the configs directory is located in the same directory as web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does not work (I no longer get anything output to my log file when I make that change).

 

I understand that one can programmatically construct a full path from the base directory, but there is surely a way to specify a relative path directly in the web.config file? I have tried modifying the string using leading slash (and backslash), etc. to no avail, and could not find a solution anywhere. Does anyone know how to do this?

 

(As an aside, using a relative path to specify the output file name within the <appender> works fine, relative to the base directory.)

 

Thanks,

 

Chris Chenier