I have an "interesting" problem in which log4net does not write log messages if they come from a workflow in ASP.NET MVC. This only seems to be the problem when I added <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> to my log4net configuration and when the website is running on my server (IIS 8.0). On my own computer, log4net logs messages just fine - even with the MinimalLock configuration, and if I delete this "MinimalLock", it will also log messages in worker threads on the server.
Here is an example:
public class MvcApplication : System.Web.HttpApplication { private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); protected void Application_Start() {
and here is my log4net configuration:
<log4net> <root> <level value="ALL" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="App_Data\log.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %level %logger - %message%newline" /> </layout> </appender> </log4net>
Without setting up MinimalLock lock, I cannot read the log file on the server, so deleting it is not really an option. I also cannot avoid logging inside workflows, since I need to log potential errors inside workers generated by Quartz.net.
I suspect this is a permissions issue on the server, but I have very limited access to the server since I am not an administrator (I basically only have FTP access - they wonβt even give me external access to the MSSQL database).
Here is the question
If my suspicion is correct, what changes should I request from the administrator of my server to fix this problem? What permissions must be granted to the user for MinimalLock to work correctly in my hosted environment?
If this is not a permissions problem, what could it be?
Any help is greatly appreciated. Thanks in advance.
Update:
After turning on the debug log for log4net, I found the following errors when I ran the above sample code (full path omitted):
log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied. log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied. log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied. log4net: ConfigureAndWatchHandler: Changed [web.config] log4net: ConfigureAndWatchHandler: Changed [web.config] log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository] log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied. log4net:ERROR [RollingFileAppender] Could not close writer [log4net.Util.CountingQuietTextWriter] log4net.Appender.FileAppender+LockingStream+LockStateException: The file is not currently locked at log4net.Appender.FileAppender.LockingStream.AssertLocked() at log4net.Appender.FileAppender.LockingStream.Flush() at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.Dispose(Boolean disposing) at System.IO.StreamWriter.Close() at log4net.Util.QuietTextWriter.Close() at log4net.Appender.TextWriterAppender.CloseWriter()
This only happens on the server.