Friday, August 30, 2013

Configuring Elmah in GAC


If you are running several applications on the same server and prefer not to configure Elmah separately for each application, you can configure Elmah in GAC. The following article was extremely helpful and covers most of the process: http://www.codeproject.com/Articles/235201/ELMAH-in-the-GAC-Using-ELMAH-from-the-Global-Assem However following it didn't really get me where I wanted and my Elmah logging still didn't work. So here is what I ended up doing.

Steps

  1. Install Elmah strongly signed assembly to GAC.
  2. Add Elmah connection string to Connection Strings in features view (IIS 7) on server level.
  3. Change .NET Framework version to 4.0
  4. Make sure all apps are running .NET 4 (in my case they are).
  5. Open C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\web.config as admin
  6. Add the following lines: 
<configsections> 
    ...
    <!-- Begin an ELMAH specific section -->
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false"
         type="Elmah.SecuritySectionHandler, Elmah, Version=1.2.14706.0, Culture=neutral, PublicKeyToken=d91c50d0d0b9de11"/>
      <section name="errorLog" requirePermission="false"
         type="Elmah.ErrorLogSectionHandler, Elmah, Version=1.2.14706.0, Culture=neutral, PublicKeyToken=d91c50d0d0b9de11"/>
    </sectionGroup>
    <!-- End an ELMAH specific section -->

</configSections>

  <!-- Begin an ELMAH specific section -->
  <elmah>
    <security allowRemoteAccess="yes" />
    <errorLog type="Elmah.SqlErrorLog, Elmah, Version=1.2.14706.0, Culture=neutral, PublicKeyToken=d91c50d0d0b9de11"
       connectionStringName="ELMAH" />
  </elmah>
    <!-- End an ELMAH specific section -->

 <!-- Begin an ELMAH specific section -->
    <location path="elmah.axd">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
    <!-- End an ELMAH specific section -->


  1. In Features View on the server level open Modules and add : Name = Elmah, Type = Elmah.ErrorLogModule, Elmah, Version=1.2.14706.0, Culture=neutral, PublicKeyToken=d91c50d0d0b9de11
  2. In Features View on the server level open Handler Mappings and add Managed Handler. Name = Elmah-Logging, Path=elmah.axd, Type = Elmah.SecuritySectionHandler, Elmah, Version=1.2.14706.0, Culture=neutral, PublicKeyToken=d91c50d0d0b9de11
  3. Make an app throw an exception.
  4. Check Elmah DB for logged errors.