Using Elmah in Windows Service, emails not send when a ELMAH error occurs.

882 views
Skip to first unread message

AjitGoel

unread,
May 21, 2008, 3:17:02 PM5/21/08
to ELMAH, ajit...@gmail.com
I have used Elmah in multiple production ASP.Net applications and it
works like a charm.
a. We have some production windows services that use Event logs for
logging errors. These are not very manageable. I would like to have a
single source for logging and reporting errors. Can Elmah be used to
log errors by windows service??
b. I am able to send emails from my application using the system.net
\mailSettings section but emails do not get triggered when an
unhandled error occurs and is logged in the elmah database. The email
settings in the elmah\errorMail section match the settings in the
system.net\mailSettings section. Here is my web.config. Could someone
look and see if I am making some obvious mistakes??

<?xml version="1.0"?>
<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="1"/>
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="ElmahConnectionString"/>
<errorMail from="ad...@abc.com" to="StarFi...@abc.com"
subject="StarFire SVASS Error" async="true" smtpPort=""
smtpServer="smtp.abc.com"/>
<errorFilter>
<test>
<equal binding="HttpStatusCode" value="404" valueType="Int32"/>
</test>
</errorFilter>
</elmah>
<system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" validate="false"/>
<add verb="POST,GET,HEAD" path="elmah.axd"
type="Elmah.ErrorLogPageFactory, Elmah"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
</httpModules>
</system.web>
<system.net>
<mailSettings>
<smtp from="ad...@abc.com">
<network host="smtp.abc.com" password="" userName="" port="25"/>
</smtp>
</mailSettings>
</system.net>
<connectionStrings>
<add name="ElmahConnectionString" connectionString="<actual
connection string>" providerName="System.Data.SqlClient"/>

</connectionStrings>

Atif Aziz

unread,
May 21, 2008, 5:22:34 PM5/21/08
to el...@googlegroups.com
>>
a. We have some production windows services that use Event logs for
logging errors. These are not very manageable. I would like to have a
single source for logging and reporting errors. Can Elmah be used to
log errors by windows service??
<<

Yes it can but it's not as magical as in ASP.NET in the sense that you can't just drop the DLL, configure the settings and go. You'll need add code to your Windows service to tell ELMAH when an unhandled exception occurs. Usually this is a single line of code, but still, it requires a change and recompilation. It's more magical in ASP.NET because the module registration causes ASP.NET to load ELMAH and connect it to the HttpApplication instance. From there, ELMAH takes over by listening to right events.

>>
b. I am able to send emails from my application using the system.net
\mailSettings section but emails do not get triggered when an
unhandled error occurs and is logged in the elmah database. The email
settings in the elmah\errorMail section match the settings in the
system.net\mailSettings section. Here is my web.config. Could someone
look and see if I am making some obvious mistakes??
<<

I think you're missing the registration of the error mailing module. You need to add the following entry as a child of the <httpModules> section:

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

- Atif

Reply all
Reply to author
Forward
0 new messages