Ok I am having a very odd issue when deploying one of our web applications to our live servers.
Our application uses log4net to log a lot of actions quite heavily and after a couple of hours after being deployed we get the following exception.
Could not load file or assembly 'log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905' or one of its dependencies. Access is denied.
Here are the relevant web.config additions I use.
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="ErrorLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="D:\SomeLocation\Errorlog"/>
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size"/>
<param name="maxSizeRollBackups" value="-1" />
<param name="maximumFileSize" value="100MB" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="FATAL" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<appender name="BookingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="D:\SomeLocation\BookingInfoLog"/>
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size"/>
<param name="maxSizeRollBackups" value="-1" />
<param name="maximumFileSize" value="100MB" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="BookingLogFileAppender"/>
<appender-ref ref="ErrorLogFileAppender"/>
</root>
</log4net>
It is working fine on our local machines an dev server but just not on the live.
Incidentally it seems to break after the JIT compiler runs on the server after a web.config update or an app pool recycle, or even just a long period of time!
UPDATE: Our live servers run all websites from a share location. I managed to replicate this issue on another server running the application from a share. When setting the site to run from a local drive the issue goes away but our hosting requires us to run from a share. Any ideas why log4net would have permissions issues running from a share. Again the app runs first time until another JIT compilation occurs
We had this problem also when we moved to VS 2010 and .NET 4.0, we don't use log4net at all, but I suspect something else we use does (maybe Crystal Reports?) and I also suspect there is a dll we use that is a 32-bit dll as well because when I change the "Enable 32-Bit Applications" option under the advanced settings for the Application Pool in IIS to "True" everything worked again.
Probally asking the obvious but I'm assuming the log4net.dll in your bin folder is the correct version ?
if you have more than one project which references differnt versions of the same DLL its not uncommon for the later project to copy the DLL over the previous version.
Assuming that you have more than one copy of log4net needing to be supported the best solution I can think of is to add probing to you config and put this version in another folder.
http://msdn.microsoft.com/en-us/library/823z9h8w.aspx
Check the version you bind in compile time (your file reference) and the version that is used runtime (first look in the GAC, then local)
Usually the version in the GAC differs from the version you have as file reference. Please check this.
Also cleanup the ASP.NET temp dir and execute IIS restart (cmd prompt -> iisreset)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With