using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Configuration; namespace ManagementSystem.Utility { class ErrorHandler { public static void WriteErrorLog(string strProgramName, Exception ex) { //產生錯誤訊息檔名 string[] strExObj = new string[5]; strExObj[0] = "檔案名稱:" + strProgramName; strExObj[1] = "錯誤時間:" + DateTime.Now.ToString(); strExObj[2] = "錯誤說明:"; strExObj[3] = ex.ToString(); strExObj[4] = "==========================================================================================================================="; string strErrorPath = ConfigurationManager.AppSettings["ErrorFilePath"] + "Err" + DateTime.Now.ToShortDateString().Replace("/","-") + ".txt"; UtilityClass.WriteFile(strErrorPath, strExObj); } } }