I would like to try to intercept and do some other processing ( export a database ) when elmah raises an error.Is there a way to do that?
2 Answers
ELMAH exposes two events in order to do this: ErrorLog_Filtering
and ErrorLog_Logged
. ErrorLog_Filtering
is called just before logging to the configured error log and ErrorLog_Logged
is called just after. You will find documentation about error filtering on the ELMAH site. ErrorLog_Logged
isn't really documented, but you can see an example of it in this article: Logging to multiple ELMAH logs.
With that said, you probably don't want to execute any long running tasks as part of ErrorLog_Logged
and ErrorLog_Filtering
. It will slow down your system. I'm not sure on what you are trying to achieve here by exporting a database on every error?

- 4,999
- 4
- 33
- 73
Yes there is way around
1.Lets Create a Project Name ElmahMvc
2.Install nuget package nuget
Install-Package Elmah.MVC
3. Raise an Exception .There you go access error log by your local url/elmah
The saving database and Emailing is bit of configuration to take ....
Lets look at it
1.Download ELMAH script form official site
2.add a database named log and run the script
3.add a connection string in web.config
<connectionStrings>
<add name="elmah" connectionString="Data Source=.;Initial Catalog=log;Persist Security Info=True;User ID=sa;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
4.Add a elmah element in web.config
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" />
<!--For Addtional Mail Config .Remove it if not need for mail on every error-->
<errorMail from="waltoncrm@waltonbd.com"
to="mrahman.cse32@waltonbd.com"
subject="Application Exception"
async="false"
smtpPort="25"
smtpServer="YourServer"
userName="uName"
password="pass">
</errorMail>
</elmah>
and mail additional
under System.WebServer
<system.net>
<mailSettings>
<smtp deliveryMethod ="Network">
<network host="smtp.gmail.com" port="587" userName="yourgmailEmailAddress" password="yourGmailEmailPassword" />
</smtp>
</mailSettings>
</system.net>
Download my sample project and Elmah script with Visual Studio 2013 akash365.com
Note:if you donot want to crash your program or use it in asp.net web form Static [WebMethod] This seems perfect
try
{
//some web method code
}
catch(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}

- 1,341
- 2
- 17
- 45