每个appdomain的webapi和未处理的exception挂钩
拥有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挂钩永远不会被调用…原因是什么 – 如何使这个工作并捕获所有未捕获的exception(在全局exception处理程序旁边 – 它将处理请求上下文中的exception)。
上述就是C#学习教程:每个appdomain的webapi和未处理的exception挂钩分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1000833.html