Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make Elmah work with UnobservedTaskException
    primarykey
    data
    text
    <p>I'm developing a asp.net mvc application. The architecture of my application as below:</p> <ol> <li>a DBAccessLayer //layer for accessing database </li> <li>a ServiceLayer //layer to connect 1 and 3. </li> <li>a WebLayer //Web UI layer</li> </ol> <p>I want to log all application exceptions including the exceptions in the TaskScheduler.UnobservedTaskException event.</p> <p>I've tested to do as below:</p> <pre><code>protected void Application_Start() { ... TaskScheduler.UnobservedTaskException += (object sender, UnobservedTaskExceptionEventArgs excArgs) =&gt; { ErrorSignal.FromCurrentContext().Raise(excArgs.Exception); excArgs.SetObserved(); }; } </code></pre> <p>but when the UnobservedTaskException event is fired, the application crashed with exception as below:</p> <pre><code> System.ArgumentNullException was unhandled Message=Value cannot be null. Parameter name: context Source=Elmah ParamName=context StackTrace: at Elmah.ErrorSignal.FromContext(HttpContext context) in c:\builds\ELMAH\src\Elmah\ErrorSignal.cs:line 67 at MyMvcApplication.&lt;Application_Start&gt;b__0(Object sender, UnobservedTaskExceptionEventArgs excArgs) in ...\Global.asax.cs:line 82 at System.Threading.Tasks.TaskScheduler.PublishUnobservedTaskException(Object sender, UnobservedTaskExceptionEventArgs ueea) at System.Threading.Tasks.TaskExceptionHolder.Finalize() </code></pre> <p>Additionally, I put the UnobservedTaskException event in the global.asax.cs of WebLayer, can it be fired when the DBAccessLayer and ServiceLayer have unobserved exceptions?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload