I’m trying to set up ELMAH for error logging in my app. Here’s my web.config:
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<security allowRemoteAccess="0" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="AppDb" />
<errorMail from="errors@site.com" to="mail@site.com" subject="Elmah Error" smtpServer="localhost" />
</elmah>
<connectionStrings>
<add name="AppDb" connectionString="Server=***;Database=***;Trusted_Connection=yes;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</httpModules>
<customErrors mode="Off" defaultRedirect="Error.aspx">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</modules>
<handlers>
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
</system.webServer>
</configuration>
My app is logging errors in the database, but e-mails aren’t getting sent out.
I don’t know if it’s because I’m on my local machine, if my web.config is wrong, or if it’s something else entirely.
I’m going to assume you have an SMTP server running on your local machine? If you do, and you’re using IIS 6 or below – you have to allow for routing from your local IP in IIS. It sounds weird, but IIS doesn’t know who your machine is and usually won’t route from localhost.
If you don’t have an SMTP server setup on your localhost – then that’s what you need. There are a number of free ones out there for development use – like hMail
http://www.hmailserver.com/