Problem with Elmah in the GAC

时间秒杀一切 提交于 2019-12-13 17:42:51

问题


I am attempting to follow this article: http://www.codeproject.com/KB/aspnet/elmahGAC.aspx

to get Elmah working from the GAC rather than needing to be setup for each application individually. Everything works locally but when the settings are set globally, Elmah stops logging. I read somewhere that if Elmah is running from the GAC then the settings should be in the "global" machine.config vs the "global" web.config but I've tried both. Right now, I'm at a point where if I add this:

<system.webServer>
<modules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=abc123" preCondition="managedHandler" />
</modules>
</system.webServer>

into my application's web.config, it picks up the rest of the settings from the global machine.config and logs successfully. To answer the obvious question, yes I have this section in the global machine.config and have even tried entering it in the global web.config but still logging won't work. Anyone have any ideas? Is there anyway to get Elmah to display its errors instead of failing quietly?

EDIT: Here is my "global" machine.config file. It's just the default one with the stuff for ELMAH added and some section groups taken out to meet the char limit. I should probably also note this is running in IIS7.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>


<configSections>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
    </sectionGroup>
  </configSections>

<connectionStrings>
<clear />
<add name="Elmah.Sql"      connectionString="IMNOTTELLING" providerName="System.Data.SqlClient" />
<add name="LocalSqlServer" connectionString="IMNOTTELLING" providerName="System.Data.SqlClient" />
</connectionStrings>

<elmah>
  <security allowRemoteAccess="0" />
  <errorLog type="Elmah.SqlErrorLog, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" connectionStringName="Elmah.Sql" />      
</elmah>

<runtime />



<system.data>
    <DbProviderFactories />
</system.data>

<system.serviceModel>
Nothing tampered with here
</system.serviceModel>



<system.web>
    <processModel autoConfig="true"/>

  <httpHandlers>
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
  </httpHandlers>

  <httpModules>
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
  </httpModules>

  <compilation>
    <assemblies>
      <add assembly="Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" />
    </assemblies>
  </compilation>

    <membership>
    Nothing tampered with here
    </membership>

    <profile>
        <providers>
            <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/"
                type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
    </profile>

    <roleManager>
        Nothing tampered with here
    </roleManager>
</system.web>


<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests ="true">
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" preCondition="managedHandler" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" preCondition="managedHandler" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" preCondition="managedHandler" />
</modules>
<handlers>
  <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah, Version=1.2.13605.0, Culture=neutral, PublicKeyToken=e50dbdd41da277ac" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>

EDIT: I installed the modules and handler in IIS directly and now it works.


回答1:


I also had problems with IIS7 on a Win7x64 install (testing for a production system). I finally got this working by putting the module and handler into the appropriate nodes in the applicationHost.config file.

C:\Windows\System32\inetsrv\config\applicationHost.config

It seems that IIS7 ignores certain areas of the main framework web.config files, instead using the applicationHost.config file for IIS settings.

Something to note about that file if you are on a 64 bit install: it seems that 32 bit applications (including Visual Studio) will appear to not see the file. It's because of some file system behavior due to the OS being 64 bit. One easy work around is to open it using an UNC path:

\\localhost\c$\Windows\System32\inetsrv\config\applicationHost.config




回答2:


I really doubt the PublicKeyToken of Elmah is abc123... You need to use the real PublicKeyToken, which you can find if you look at the assembly in the GAC. It looks something like: b03f5f7f11d50a3a (that was for mscorlib.dll, so that is Microsoft's public key token).




回答3:


EDIT: I installed the modules and handler in IIS directly and now it works.




回答4:


I've tried everything I could find to get ELMAH working from the GAC on my Win7 Ultimate 64bit machine and the only thing that finally got it working was registering the elmah.axd handler and the various modules in IIS Manager.



来源:https://stackoverflow.com/questions/7083927/problem-with-elmah-in-the-gac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!