首先,我很抱歉什麼是重複的帖子。我似乎無法將搜索範圍縮小到足夠的範圍,因此Google和Google都能找到我要找的內容。C#:我可以從CLR的未處理異常中獲取詳細信息嗎?
我目前在一家店裏工作,他們喜歡他們的例外氣泡。當編譯的應用程序進行測試時,嘗試獲取異常的詳細信息(消息和堆棧跟蹤)是一個很大的麻煩。 Windows顯示那個熟悉的盒子,沒有任何細節。
經過近一個小時的測試,發現測試盒中的水晶報告版本錯誤,我添加了這個簡單的代碼,可能很熟悉。
static void Main(string[] arg)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(...);
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).ToString());
}
這幹得不錯,但我不允許託運。有沒有在App.config或通過註冊表設置任何辦法讓CLR顯示或記錄異常詳細信息編譯.net應用程序?
在此先感謝您的幫助。
你不能用日誌替換你的MessageBox調用,然後重新拋出異常嗎? – 2010-01-12 16:39:32
您是否看過插入日誌記錄DLL,如log4net或EnterpriseLibrary日誌記錄,然後按照Martin的建議進行操作? – Paddy 2010-01-12 16:43:46