string exceptionLogFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"Exception.txt");
private void checkBoxTopMost_CheckedChanged(object sender, EventArgs e)
{
try
{
this.TopMost = this.checkBoxTopMost.Checked;
}
catch (Exception ex)
{
StackFrame fr = new StackFrame(true);
StackTrace st = new StackTrace(fr);
MethodBase mb = fr.GetMethod();
recordExceptionLog(ex, mb.Name, fr.GetFileLineNumber(), st.ToString());
}
}
/// <summary>
/// Record Exception Message to Log File
/// </summary>
private void recordExceptionLog(Exception ex, string methodName, int lineNumber, string stackTraceString)
{
string exMessage = String.Format("{0}{1}\t[{2}:{3}] {4}",
DateTime.Now.ToString(), stackTraceString, methodName, lineNumber, ex.Message);
using (StreamWriter sw = new StreamWriter(exceptionLogFile, true))
{
sw.WriteLine(exMessage);
}
}
private void checkBoxTopMost_CheckedChanged(object sender, EventArgs e)
{
try
{
this.TopMost = this.checkBoxTopMost.Checked;
}
catch (Exception ex)
{
StackFrame fr = new StackFrame(true);
StackTrace st = new StackTrace(fr);
MethodBase mb = fr.GetMethod();
recordExceptionLog(ex, mb.Name, fr.GetFileLineNumber(), st.ToString());
}
}
/// <summary>
/// Record Exception Message to Log File
/// </summary>
private void recordExceptionLog(Exception ex, string methodName, int lineNumber, string stackTraceString)
{
string exMessage = String.Format("{0}{1}\t[{2}:{3}] {4}",
DateTime.Now.ToString(), stackTraceString, methodName, lineNumber, ex.Message);
using (StreamWriter sw = new StreamWriter(exceptionLogFile, true))
{
sw.WriteLine(exMessage);
}
}
'Code > C#' 카테고리의 다른 글
| [C#] Windows UI Automation Sample (0) | 2010.04.13 |
|---|---|
| [C#] indexer sample (0) | 2010.02.23 |
| [C#] Shift Operator (0) | 2010.02.17 |
| [C#] Register/Unregister ActiveX Control (0) | 2009.03.15 |
| [C#] Detect UserControl's Closing (0) | 2009.01.07 |