내용으로 건너뛰기
사용자 도구
로그인
사이트 도구
도구
문서 보기
이전 판
백링크
최근 바뀜
미디어 관리
사이트맵
로그인
최근 바뀜
미디어 관리
사이트맵
기술자료
작업공간
개인공간
사이트맵
추적:
kb:csharpdebugging
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== C# Debugging ====== .NET 환경에서의 디버깅 ====== 예외 발생시 콜스택 파일에다 기록하기 ====== WinForms 애플리케이션의 경우에는 Application.ThreadException 핸들러를 지정해주면 되고, 콘솔 애플리케이션의 경우에는 AppDomain.CurrentDomain.UnhandledException 핸들러를 지정해주면 된다. <code c#> using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using System.Windows.Forms; using System.Threading; namespace YourNameSpace { class DebugHelper { public static void InstallExceptionHandler() { Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionHandler); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); } private static void ThreadExceptionHandler(object sender, ThreadExceptionEventArgs args) { HandleException((Exception)args.Exception); } private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { HandleException((Exception)args.ExceptionObject); } private static void HandleException(Exception e) { // unmanaged exception인 경우 e가 null로 넘어온다. // 처리해야 하는데... 귀찮다. StreamWriter file = new System.IO.StreamWriter( Application.StartupPath + "\\error.log", false, System.Text.Encoding.Default ); file.WriteLine(e.StackTrace); file.Close(); MessageBox.Show( "A fatal problem has occurred.\n" + e.Message + "\nin: " + e.GetType(), "Program Stopped", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); Trace.Close(); Process.GetCurrentProcess().Kill(); } } } </code> 프로그램 초기화 하는 부분 어딘가에서 InstallExceptionHandler 호출해 준다. <code c#> DebugHelper.InstallExceptionHandler(); </code> ====== 링크 ====== * [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/DBGch01.asp | Production Debugging for .NET Framework Applications]] * [[http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx | SOS: It's Not Just an ABBA Song Anymore]] ---- * see also [[CSharp|C#]]
kb/csharpdebugging.txt
· 마지막으로 수정됨: 2014/11/07 16:23 (바깥 편집)
문서 도구
문서 보기
이전 판
백링크
맨 위로