views:

3621

answers:

4

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

A: 

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)

Patrick Peters
But if we don't reference the GAC we just reference the dll. Maybe my understanding of the GAC is incorrect?
Sheff
Reference assemblies is always build-time, GAC is always runtime. Click on the assembly that is referenced in your C# project. Look at the signature. Then look in the GAC, check whether the assembly name is registered there. If so, check both versions (the one you referenced and the one in the GAC). When they differ you have a problem
Patrick Peters
+1  A: 

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

Saint Gerbil
Thats interesting, We do have several projects running on that server using log4net. I'm pretty sure they use the same version though, I will try your suggestion. Even so why would running the project from a local drive work ok but not from a share?
Sheff
A Share is only a partially trusted location by default you can add it to have full trust, I forget the command prompt name but there is ".NET Framework 2.0 Configuration" mmc Snap-in which can conifgure it for you.Can you confirm that the version of log4net in your bin folder is version 1.2.9.0 and that the public key is correct? you can right click on the file and choose properties to find out.
Saint Gerbil
A: 

I'm having a similiar problem. I have 2 IIS with websites pointing to a Network Drive.

the error is : Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken)1b44e1d426115821' or one of its dependencies. Logon failure: unknown user name or bad password. (Exception from HRESULT : 0x8007052E)

I do not have log4net installed in the GAC.

The share as Fulltrust for URL : file://\

If temporary files are deleted the web application works fine until app_pool restart.

Nuno Costa
A: 

Hi Nuno,

I am having exactly the same problem as you in the same scenario: no log4net.dll in the GAC and pointing to a network drive with full trust.

Could you please tell me if you found any solution?

Thanks in advance, Belen

Belen