捕捉Windows服务与WinForm的全局异常是有差别的。
1.先看Windows服务的:
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)
{ }
}
2.关于WinForm的全局异常捕捉,请链接
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务