webapi and unhandled exception hook per appdomain

早过忘川 提交于 2019-12-23 01:12:52

问题


Having a WebApi 2.2 application - is it possible to make use of AppDomain's UnhandledException hook?

I have a code similar to this:

[assembly: OwinStartup("DevConfiguration", typeof(DevStartup))]
namespace WebApi.Module
{
  public class DevStartup
  {
     private const string ErrorEventSourceName = "WebApiHost";
     private const int ErrorEventId = 600;

     [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
     public void Configuration(IAppBuilder app)
      {

         AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
          ...
          throw new Exception("some exception);
       }
    public static void AppDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
    {
        EventLog.WriteEntry(ErrorEventSourceName, ex.ToString(),EventLogEntryType.Error, ErrorEventId);
    }
   }
}

The UnhandeledException hook is never called... What is the reason - how to make this work and catch all the uncaught exceptions (beside a global exception handler - which would handle exceptions on request contexts).

来源:https://stackoverflow.com/questions/29257188/webapi-and-unhandled-exception-hook-per-appdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!