public partial class MonitorOnServer : ServiceBase
{
public MonitorOnServer()
{
InitializeComponent();
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = e.ExceptionObject as Exception;
Log.Instance.AddLog("来自“MonitorOnServer”的全局异常。" + ex.Message + "详细信息如下:"
+ Environment.NewLine + "[InnerException]" + ex.InnerException
+ Environment.NewLine + "[Source]" + ex.Source
+ Environment.NewLine + "[TargetSite]" + ex.TargetSite
+ Environment.NewLine + "[StackTrace]" + ex.StackTrace);
Log.Instance.WriteLog(strLogPath);
}
catch { }
}
protected override void OnStart(string[] args)
{ }
protected override void OnStop(string[] args)
{ }
}
捕捉Windows服务与WinForm的全局异常
原创
©著作权归作者所有:来自51CTO博客作者282030166的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot优雅捕捉异常的两种方法
SpringBoot优雅捕捉异常的两种方法
SpringBoot 异常处理 @ControllerAdvice @ExceptionHandler -
SpringMVC中异常处理与ControllerAdvice捕捉全局异常
SpringMVC通过HandlerExceptionResolver处理程序的异常,包括handler映射、数据绑定以及目标方法的执行时发生的异常。异常处理顺序:
异常处理 spring mvc spring mvc json -
关于C# 全局异常捕捉系统
-
Kotlin 协程异常全局捕捉
新建 resources\META-INF\services\kotlinx.coroutines.CoroutineExceptionHan\
kotlin android java ide 后缀