log4net doesn't create log file when deployed on IIS7

asp.net, iis-7, log4net

Solution

It could be that you do not have permissions to write to the file 'log.txt'.

I don't know what the current directory would be but it's unlikely to be somewhere IIS can write to.

You need to create a folder somewhere and grant access for IIS to write to it, I understand you need to grant access to the IIS_IUSRS group and then specify the absolute path to that file. e.g.

<param name="File" value="D:\Logs\log.txt" />

..using the path to your preferred location.

Problem

Good morning everybody, I have a log4net issue that didn't exist when I was developing on my local machine, but once I deployed the application to a server, log4net stopped working. This is the server configuration : -Windows XP SP3 -IIS 7 -framework .Net v4 This is the log4net configuration in the web.config of the website: ``` <configuration> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log.txt" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="30MB" /> <staticLogFileName value="false" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" /> </layout> </appender> </log4net> </configuration> ``` I also have a class library and this is its App.config file: ``` <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> </configSections> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > <param name="File" value="log.txt" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="30MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" /> </layout> </appender> </log4net> </configuration> ``` This is how I call the log function on every class: ``` private static readonly ILog log = LogManager.GetLogger(typeof(AppDomain)); ``` ...and this is how i call it : ``` log.Error("\n\t=>" + ex.GetBaseException().Message + "\n\r" + " @ " + Environment.StackTrace); ```

Original source