問題
使用 Exception自訂義寫log的方法
解決方法
/// /// 傳入Exception /// public WriteLog(Exception ex) { StreamWriter sw = new StreamWriter("c:\\test.txt", true); sw.WriteLine("================================================"); sw.WriteLine("Datetime :" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); sw.WriteLine("Source :" + ex.Source); sw.WriteLine("StackTrace :" + ex.StackTrace); sw.WriteLine("Message :" + ex.Message); sw.WriteLine("InnerException:" + ex.InnerException); sw.Close(); sw.Dispose(); }
沒有留言:
張貼留言