Recently, I've noticed that a web application in IIS is restarting randomly, sometimes every 20 minutes. I've checked the Event Log, and found various errors of:
- Level: Error
- Source: .Net Runtime
- EventID: 1026
Below is the exception details:
Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.FormatException
Stack:
at System.Text.StringBuilder.AppendFormat(System.IFormatProvider, System.String, System.Object[])
at System.String.Format(System.IFormatProvider, System.String, System.Object[])
at Elmah.ErrorMailModule.ReportError(Elmah.Error)
at Elmah.ErrorMailModule.ReportError(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
I am using the latest stable version of Elmah (1.2.2). Below is the <elmah>
configuration node in web.config
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/errors/" />
<security allowRemoteAccess="1" />
<errorMail from="[email protected]" to="errors@casasoft-dev" subject="{Error_Encountered} [Visit Gozo]"
async="true" smtpPort="25" smtpServer="mail.casasoft.com.mt" userName="errors@casasoft-automailer" password="RvjyBiyvePVVpcLBNgJ6" />
</elmah>
I am setting it to send such emails in async-mode (async="true"). If these are spawned on a background thread, and an error occurs on a backgroung thread, as far as I know the process is terminated.
Any ideas what can be done?
I am using IIS7, and ASP.Net MVC 4.
I've raised an issue on Google Code related to ELMAH, and I got a reply from one of the developers.
Basically, it seems that the email subject is internally in Elmah using
string.Format()
to format it with the error message {0}, and error type {1}. In my case, the subject I specified in the settings was:The
{}
where triggering a FormatException, hence the issue. This was easily resolved by replacing these with round-brackets, as I had no need for the curly brackets. One could escape them by doing{{
and}}
, but in my case it was unnecessary.