Got this answer from Atif Aziz (ELMAH Lead contributor) on the ELMAH google group:
When you use
Task.Run
, theHttpContext
is not transferred to the thread pool thread on which your action will execute. WhenErrorSignal.FromCurrentContext
is called from within your action, my guess is that it's probably failing with another exception because there is no current context. That exception is lying with the Task. If you're on .NET 4, you're lucky because you'll see the ASP.NET app crash eventually (but possibly much after the fact) when the GC will kick in and collect the Task and its exception will go “unobserved”. If you're on .NET 4.5, the policy has been changed and the exception will simply get lost. Either way, your observation will be that mailing is not working. In fact, logging won't work either unless you useElmah.ErrorLog.GetDefault(null).Log(new Error(ex))
, where a null context is allowed. But that call only logs the error but does not do any mailing. ELMAH's modules are connected to the ASP.NET context. If you detach from that context by forking to another thread, then you cannot rely on ELMAH's modules. You can only useElmah.ErrorLog.GetDefault(null).Log(new Error(ex))
reliably to log an error.