- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 WCF 服务,在 Global.asax 中有以下代码:
protected void Application_Start(object sender, EventArgs e)
{
// Make sure that any exceptions that we don't handle at least get logged.
AppDomain.CurrentDomain.UnhandledException += LogUnhandledException;
}
private void LogUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.Error.LogException("UnhandledException", e.ExceptionObject as Exception);
}
想法是至少记录所有未处理的异常。
但它似乎从来没有被调用过。我尝试在我的一个服务操作中执行除以零操作,它在遇到异常后就停止了服务。
int zero = 0;
int result = 100 / zero;
LogUnhandledException 方法永远不会被调用。
我在 IIS 和调试器中都试过了。
我怎样才能让这个事件为 WCF 服务工作?
最佳答案
unhandled exception filter for an app domain是允许应用程序在终止之前记录有意义的信息的最后尝试。
This event provides notification of uncaught exceptions. It allows the application to log information about the exception before the system default handler reports the exception to the user and terminates the application.
如果 WCF 允许以这种方式完全不处理服务抛出的异常,则意味着当服务托管在 IIS 中时,整个工作进程将终止,因为单个请求引发了异常——这不是理想的结果。因此,WCF 不会留下未处理的服务抛出的异常 - 在这种情况下不会引发此事件。
如果您想记录 WCF 服务抛出的异常,请查看 IErrorHandler
interface相反。
关于c# - AppDomain.CurrentDomain.UnhandledException 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16348797/
所以我的问题围绕着节省内存。 本质上,我需要将程序集加载到主域/当前域以外的单独应用程序域中,检查该程序集中的类型,然后在完成后卸载新域。 目前我的解决方案如下: AppDomain NewDomai
我想枚举 Asp.NET 应用程序中所有加载的程序集,使用 AppDomain.CurrentDomain.GetAssemblies() .但是,在检查 AppDomain 的文档时,我发现以下语句
当我需要在关闭应用程序之前使用 Stop() 函数停止后台线程时,我有一个简单的应用程序。问题是我的 Main() 函数有几个退出点(返回语句) static void Main(string[] a
我有一个带有绑定(bind)到 Application.CurrentDomain.UnhandledException 的事件处理程序的 .NET 程序。 运行带有调试的程序时,当抛出未处理的异常时
我有一个全局异常处理程序,可以在Main.cs中很好地工作,但是在捕获到错误后,我的应用程序不存在了,而只是挂起了。我尝试了Environment.Exit,退出选择器,返回,重新抛出异常-所有这些仍
我目前正在使用以下代码: AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var name = args.Name
我想在发生未处理的异常时在问题跟踪器系统中创建错误报告。由于这是通过一系列异步http请求完成的,所以对应的方法是async return a task: AppDomain.CurrentDomai
我在单独的类库项目中有电子邮件模板(和电子邮件发送器)。我正在获取 View 路径(复制到输出目录 = true),如下所示: var basePath = AppDomain.CurrentDoma
在 VS2012 中,我有一堆 (MS) 单元测试,它们使用我存储在与测试文件类相同的文件夹中的不同 xml/文本文件。 我使用 File.OpenRead(AppDomain.CurrentDoma
我有一个程序集,当访问它时,它会启动一个线程来处理放置在队列中的项目。在该程序集中,我将一个处理程序附加到 DomainUnload 事件: AppDomain.CurrentDomain.Domai
我想遍历我在项目中添加的所有类 Assembly[] foo = AppDomain.CurrentDomain.GetAssemblies(); foreach(Assembly a in foo)
我有一个 WCF 服务,在 Global.asax 中有以下代码: protected void Application_Start(object sender, EventArgs e) {
我正在尝试使用 CurrentDomain.AssemblyResolve 事件来加载标记为嵌入式资源的 DLL。具体来说,我的问题来自于我试图将程序集用作子类的事实,如下所示: #define BR
我试图根据答案实现解决方案 How to handle exceptions raised in other threads when unit testing? ,但我仍然不明白在处理程序中做什么。
我已经设置了 UnhandledException 以在我的服务崩溃之前记录任何异常。 AppDomain.CurrentDomain.UnhandledException += new Unhand
在找到关于程序集解析 (AppDomain.CurrentDomain.AssemblyResolve asking for a .resources assembly?) 的最后一个问题的答案后,我
如何将 AppDomain.CurrentDomain.BaseDirectory 的相对路径获取到 Uri 中。 我需要从 AppDomain.CurrentDomain.BaseDirectory
总的来说,我试图从主域中的 dll 执行方法,但之后,卸载该 dll。到目前为止,我已经创建了新的 AppDomain 并在那里加载了 Assembly\dll,使用 MarshalByRefObje
我遇到了一个问题,我的单元测试没有在我的 TFS 构建机器上运行,尽管它们正在我的开发人员机器上运行。 我在以下行中遇到异常,试图为特定接口(interface)加载所有加载的程序集: var
我在使用 ReSharper (8.2.2) 和 VS 2013 运行我的测试用例时遇到了一个奇怪的错误。 演示该问题的简化测试用例仅包含两行代码: CallContext.LogicalSetDat
我是一名优秀的程序员,十分优秀!