locked
Error Logging with Elmah RRS feed

  • Question

  • User1870461982 posted

    I am using Elmah for error logging, which works fine on the local system but on Live site it doesn't work.

    In my web.config

     <customErrors mode="RemoteOnly" defaultRedirect="error.aspx">
          <error statusCode="404" redirect="~/error404.aspx"/>
        </customErrors>

    So whenever error occurs the control goes to error.aspx page and elmah is unable to record the error.

    Let me know how i can redirect to error.aspx page as well as log the error

    Friday, April 8, 2011 11:19 PM

Answers

  • User1508394307 posted

    For IIS7 in integration mode you need to add 

        <system.webServer>
            <modules>
                <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorTweet" type="Elmah.ErrorTweetModule, Elmah" preCondition="managedHandler" />
            </modules>
            <handlers>
                <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
            </handlers>
        </system.webServer>

    See ELMAH documentation for more details.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 10, 2011 4:47 AM

All replies

  • User1508394307 posted

    And what type of logging did you choose? XmlFileErrorLog? Check permissions on the folder where you supposed to save log files. Check if dll for elmah has been copied to \bin, check again web.config configuration.

    Sunday, April 10, 2011 4:09 AM
  • User1870461982 posted

    And what type of logging did you choose? XmlFileErrorLog? Check permissions on the folder where you supposed to save log files. Check if dll for elmah has been copied to \bin, check again web.config configuration.

     

    I have choosen error file log as well as e-mail

     

    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
          

    None of them work on the live server but they both work fine on local system. Also checked the file permisison, it has full acess for log folder.

    elmah dll is there in the bin folder

     

    Sunday, April 10, 2011 4:20 AM
  • User1870461982 posted

    My web.config file

    <?xml version="1.0"?>
    <configuration>
    	<configSections>
    		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				</sectionGroup>
    			</sectionGroup>
    		</sectionGroup>
        
        <sectionGroup name="elmah">
          <section name="security" type="Elmah.SecuritySectionHandler, Elmah" />
          <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
          <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
        </sectionGroup>
        
    	</configSections>
    
      <elmah>
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/Error/Log" />
        <errorMail subject="Error Test" to="test@test.com" from="test@test.com" />
        <security allowRemoteAccess="yes" />
      </elmah>
      
    	<appSettings/>
    	<connectionStrings>
    		<remove name="LocalSqlServer"/>
        
       
        <add name="LocalSqlServer" connectionString="server=test;database=test;uid=test;pwd=test*;" providerName="System.Data.SqlClient"/>
        <add name="ELMAH.SQLite" connectionString="Data Source=|DataDirectory|errors.s3db"/>
        
        <!--  
        <add name="LocalSqlServer" connectionString="Data Source=test-PC;Initial Catalog=test; Integrated Security=true" providerName="System.Data.SqlClient"/>
    -->
      </connectionStrings>
    	<system.web>
    		<compilation debug="true">
    			<assemblies>
    				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    				<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
    		</compilation>
    		<membership>
    			<providers>
    				<clear/>
    				<add name="AspNetSqlMembershipProvider" 
                 type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
                 connectionStringName="LocalSqlServer" 
                 enablePasswordRetrieval="false" 
                 enablePasswordReset="true" 
                 requiresQuestionAndAnswer="false" 
                 requiresUniqueEmail="true" 
                 passwordFormat="Hashed" 
                 maxInvalidPasswordAttempts="5" 
                 minRequiredPasswordLength="7" 
                 minRequiredNonalphanumericCharacters="1" 
                 passwordAttemptWindow="10" 
                 passwordStrengthRegularExpression="" 
                 applicationName="test"/>
    			</providers>
    		</membership>
    		<!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            -->
        <authentication mode="Forms">
          <forms timeout="200" slidingExpiration="true" name="frmSub" loginUrl="~/Login"></forms>
          
        </authentication>
    
        <customErrors mode="Off"> </customErrors>
    
        <!--
        <customErrors mode="RemoteOnly" defaultRedirect="error.aspx">
          <error statusCode="404" redirect="~/error404.aspx"/>
        </customErrors>
    -->
    
    
        <!--
                The <customErrors> section enables configuration 
                of what to do if/when an unhandled error occurs 
                during the execution of a request. Specifically, 
                it enables developers to configure html error pages 
                to be displayed in place of a error stack trace.
    
            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    		<pages>
    			<controls>
    				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			</controls>
    		</pages>
    		<httpHandlers>
    			<remove verb="*" path="*.asmx"/>
    			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
          <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
        </httpHandlers>
    		<httpModules>
          
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
          <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
          
    			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</httpModules>
    		<machineKey decryption="AES" validation="SHA1" decryptionKey="D8F35812CB56D06F8151A0870A215FF115CA339A8121412DE8453B547C7F1B33" validationKey="2760378FD5DB4CB3FEB546126F42302EE4B214D9E543FF17C5C220C59C5045F8"/>
    		<roleManager enabled="true"/>
    	</system.web>
    	<system.codedom>
    		<compilers>
    			<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    		</compilers>
    	</system.codedom>
    	<!-- 
            The system.webServer section is required for running ASP.NET AJAX under Internet
            Information Services 7.0.  It is not necessary for previous version of IIS.
        -->
    	<system.webServer>
    		<validation validateIntegratedModeConfiguration="false"/>
    		<modules>
    			<remove name="ScriptModule"/>
    			<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</modules>
    		<handlers>
    			<remove name="WebServiceHandlerFactory-Integrated"/>
    			<remove name="ScriptHandlerFactory"/>
    			<remove name="ScriptHandlerFactoryAppServices"/>
    			<remove name="ScriptResource"/>
    			<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</handlers>
    	</system.webServer>
    	<runtime>
    		<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    		</assemblyBinding>
    	</runtime>
    
      <!-- e-Mail credentials -->
      <system.net>
        <mailSettings>
          <smtp deliveryMethod="Network" from="test@test.co.uk">
            <network host="mail.test.co.uk" userName="test@test.co.uk" password="test" port="25"/>
          </smtp>
        </mailSettings>
      </system.net>
    
      <location path="elmah.axd">
        <system.web>
          <authorization>
             <deny users="?" />
          </authorization>
        </system.web>
      </location>
      
    </configuration>
    

     

    Sunday, April 10, 2011 4:27 AM
  • User-1011137159 posted

    Below is the good link for that...

    http://amitpatelit.wordpress.com/2011/04/05/error-handling-mechanisms-in-asp-net-application/

    Sunday, April 10, 2011 4:31 AM
  • User1508394307 posted

    For IIS7 in integration mode you need to add 

        <system.webServer>
            <modules>
                <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorTweet" type="Elmah.ErrorTweetModule, Elmah" preCondition="managedHandler" />
            </modules>
            <handlers>
                <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
            </handlers>
        </system.webServer>

    See ELMAH documentation for more details.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 10, 2011 4:47 AM
  • User1870461982 posted

    For IIS7 in integration mode you need to add 

        <system.webServer>
            <modules>
                <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
                <add name="ErrorTweet" type="Elmah.ErrorTweetModule, Elmah" preCondition="managedHandler" />
            </modules>
            <handlers>
                <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
            </handlers>
        </system.webServer>

    See ELMAH documentation for more details.

    still no luck. I have IIS 7 on local system and iis 7 on live server also. Local system it works fine but live server it doesn't

     

     

    Sunday, April 10, 2011 4:58 AM
  • User1870461982 posted

    I forgot to mention. The shared hosting server i am using has blocked outgoing access on port no 80. could that cause a problem?

    Sunday, April 10, 2011 5:03 AM
  • User1870461982 posted

    It's working now. Thanks

    Sunday, April 10, 2011 5:13 AM