void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
string Message = string.Empty;
Message = "Url" + Request.Path + Server.GetLastError().ToString();
//不存在 就建立資料夾 預設 C:\\Trioptics
string sPath = @"C:\\MGSLog";
if (!Directory.Exists(sPath))
{
Directory.CreateDirectory(sPath);
}
string sLogFileName = sPath + "\\Log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
System.IO.FileInfo fi = new FileInfo(sLogFileName);
FileStream fs = fi.Open(FileMode.Append, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(String.Format("{1} | {0} | --> {1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff"), Message + e.ToString());
sw.Close();
fs.Close();
}