Log4Net Relative Path To External Config

11,997

I had the same issue. I wanted to create a folder called Logs in my solution and put all the logs inside it but it was not working without a drive letter.

I was adding a backslash before the folder name and after removing it worked.

<file value="Logs\RedmineTaskCreator.log" />

Just make sure the Logs folder exists. I'm not sure whether log4net will create the folder. Hope it works for you.

Share:
11,997
OneClutteredMind
Author by

OneClutteredMind

Live as if you'll die today but dream as if you'll live forever!

Updated on June 04, 2022

Comments

  • OneClutteredMind
    OneClutteredMind over 1 year

    I have a situation where I reference an external Log4Net Configuration File from my web root config. However, it's my individual applications that inherit the web root config and in turn reference the external Log4Net Config file.

    This all works fine and dandy if I have a hard coded path to the Log4Net Config. Ex: c:\inetpub\wwwroot\logging.config

    What I'd like to do is reference this logging.config without having to specify a drive letter or preferably via a relative path. This will make it easy to switch environments in the case where the websites now exist on the E:\ or D:\ or F:\ drives.

    I tried referencing the file in this form: \inetpub\wwwroot\logging.config - but Log4Net doesn't seem to pick it up.

    I've also considered grabbing the drive letter from HttpRuntime.AppDomainAppPath in code but it seems so hack'ish.

    Has anyone come up with a fancy method to reference an external Log4Net configuration file using reference paths instead of hard coded paths?

    Thank a bunch in advance for any help. :)