错误记录和屏幕截图. [英] Error Logging and Screen Shot.
问题描述
我的应用程序是在c#.net 3.5中设计的,
我想处理运行应用程序时发生的未处理异常!
我怎样才能做到这一点?我用谷歌搜索了这个问题,但是找不到答案!
我如何收集错误日志,因为我的应用程序是客户端服务器,所以我需要在集中位置收集所有错误.
另外,当出现Erros时,我还需要一张表格的屏幕截图,您能提出任何建议吗?发生错误时应何时捕获?
Prathamesh
Hi,
My Application is Designed in c#.net 3.5,
I want to Handle Unhandled Exceptions occured while running the application!
How can i do this? I Googled this Question but cant find answer!
How can i collect the Log of Errors, As my Application is Client Server, I need to Collect ALl the Errors on the centralised Place.
Also I need a screen shot of the Form when Erros occur, can you suggest any Idea When should i capture when error Occurs?
Prathamesh
推荐答案
以下是为您准备的代码示例,因为真的很高兴知道:
Here is a code sample for you, as it''s really good to know:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//...
Application.ThreadException += delegate(object sender, System.Threading.ThreadExceptionEventArgs e) {
MessageBox.Show(
string.Format("{0}:\n{1}", e.Exception.GetType().Name, e.Message),
string.Format(" {0}: Exception", Application.ProductName),
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}; //Application.ThreadException
我通常从应用程序入口点(Main
)调用第一行,其余部分-构成主窗体的构造函数.
I usually call first line from application entry point (Main
), and the rest of it — form a constructor of a main form.
您可以处理Application.ThreadException
事件,以处理在主应用程序线程中引发的所有未处理的异常.要捕获非Windows窗体创建和拥有的线程中发生的异常,请使用AppDomain.UnhandledException.
You can handle the Application.ThreadException
event to handle all unhandled exceptions that are thrown in the primary application thread. To catch exceptions that occur in threads not created and owned by Windows Forms, use the AppDomain.UnhandledException.
这篇关于错误记录和屏幕截图.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!