OneClutteredMind
OneClutteredMind

Reputation: 459

Log4Net Relative Path To External Config

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. :)

Upvotes: 4

Views: 14101

Answers (2)

Andy
Andy

Reputation: 11492

In my case I was running asp.net in the debugger and I found that a relative log file path was relative to the bin/debug directory, not the current working directory of the program. Not sure what that would mean for IIS though

Upvotes: 0

Adrian Hedley
Adrian Hedley

Reputation: 1569

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.

Upvotes: 13

Related Questions