No Signs of Fatal Exception when application crashes | NLog version 2 | Compact Framework 3.5

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:26:44

问题


I have a .Net Compact Framework 3.5 application that uses Nlog version 2.0 to log Info, Error and Fatal Exceptions. Most of the time the logging works as expected and logs fatal exceptions before crashing. But at times it is observed that application crashes without leaving any signs of an error/exception.

Let me elaborate the scenario:

  1. The Application creates few threads, all the threads have try-catch block added at the beginning of their call stacks. And hence log fetal exceptions before crashing.
  2. The main thread have 'AppDomain.CurrentDomain.UnhandledException' to log any fetal exceptions on its call stack.
  3. The application does load some third party managed dlls and performs some PInvokes on Wnce dlls.

But I believe even if some third party DLL crashes (or let’s say it creates a new thread which crashes), I should at least see some ThreadAbortExceptions in the log, logged by my application's thread before exiting.

The key configuration parameters of Nlog are:

a. FileTarget.AutoFlush = true

b. FileTarget.KeepFileOpen= false

c. FileTarget is not wrapped in any async wrapper or in any buffered wrapper.

Please let me know if I'm missing anything.


回答1:


Possible reasons for the crash include OutOfMemory exception or StackOverflowException. From the documentation for the latter:

Version Considerations

In prior versions of the .NET Framework, your application could catch a StackOverflowException object (for example, to recover from unbounded recursion). However, that practice is currently discouraged because significant additional code is required to reliably catch a stack overflow exception and continue program execution.

Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop. Note that an application that hosts the common language runtime (CLR) can specify that the CLR unload the application domain where the stack overflow exception occurs and let the corresponding process continue. For more information, see ICLRPolicyManager Interface and Hosting Overview.



来源:https://stackoverflow.com/questions/8730716/no-signs-of-fatal-exception-when-application-crashes-nlog-version-2-compact

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