I’m working with a WCF web service project and using log4net, but can’t get it to write to the log unless I use an external log4net config file that’s in some safe directory, like C:\temp, and create the log also in some safe directory like C:\temp.
What I mean by “safe” directory is really any directory that’s not under C:\users, or C:\inetpub\wwwroot. If I try to have the log4net config file or the log itself in the C:\inetpub\wwwroot\<projectName> folder where my service is deployed, it just does nothing (no errors, just no log is created and nothing happens). But if I load config from a log4net config file under C:\temp, and write my log to C:\temp, it works fine.
I don’t want to use C:\temp though, I want the log to be in inetpub where the service is deployed, right there with the web.config. I know this is obviously a user permissions issue, but what can be done about it?
Also, I can’t get it to read any log4net config from the web.config file; that’s why I tried using an external log4j config file in the first place.
I’ve read quite a few posts here, and followed their instructions to set everything up. I just need a push in the right direction on what’s best practice to store log4net config for an IIS hosted WCF webservice, and what I can do to be able to store my log in wwwroot/<myprojectfolder>
One of the posts I read was this one… log4net in WCF hosted by IIS 7.5 no write log file
Here’s what I’ve got thus far…
In a AssemblyInfo.cs file I have the following. I’ve tried both ways of specifying a config file, and of letting it try to use web.config by not specifying a config file.
//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
In Global.asax that I had to add manually I have the following. If I specify a file in a safe directory like C:\temp when I call Configure() it works…
XmlConfigurator.Configure();
var logger = LogManager.GetLogger(typeof(Global));
logger.Info("Starting up services");
And in my service implementation file, I have this…
private static readonly log4net.ILog logger = log4net.LogManager.GetLogger
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Any ideas?
EDIT
I’m using Windows 7 Pro x86 with VS2008 for my dev box and deploying on the local IIS.
I’m a dummy… I worked on this for way too long, then finally asked a StackOverflow question, and just by asking the question I must have knocked something loose in my brain that made me think to just go muck with permissions.
I fixed this by giving Write and Modify permissions to my IUSR, NETWORK SERVICE and IIS_IUSRS users for the folder where my service is deployed. And voila it works.
Not sure that all those users need permissions, but at least one of them did.
Anyways, problem solved.
Hope this helps someone else, and props to the SO community anyways on being so awesome.