每个appdomain的webapi和未处理的异常挂钩

时间:2015-03-25 13:33:38

标签: c# exception-handling asp.net-web-api2 appdomain

拥有WebApi 2.2应用程序 - 是否可以使用AppDomain的UnhandledException钩子?

我有类似的代码:

[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);
    }
   }
}

永远不会调用UnhandeledException挂钩... 原因是什么 - 如何使这项工作能够捕获所有 未被捕获的 异常(在全局异常处理程序旁边 - 它将处理请求上下文中的异常)。

0 个答案:

没有答案
相关问题