/// <summary>
/// 寫log add by Rain 做测试用
/// </summary>
/// <param name="Logmessage"></param>
public void WriteLog(string Logmessage)
{
string logtime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
string logfilename = "AutoRejectServicelog" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
//string savePath =System.Web.HttpContext.Current.Server.MapPath(@"log");
//string savePath = AppDomain.CurrentDomain.BaseDirectory + @"log";
string savePath = "C:\AutoReject\log";
if (!System.IO.Directory.Exists(savePath))
{ //需要注意的是,需要对这个物理路径有足够的权限,否则会报错
//另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
System.IO.Directory.CreateDirectory(savePath);
}
Logmessage = "記錄執行步驟信息:進入該事件時間:" + logtime + "
" + "相關信息:
" + Logmessage + "
";
System.IO.StreamWriter fd = new System.IO.StreamWriter(savePath + "\" + logfilename, true, System.Text.Encoding.Default);
fd.WriteLine(Logmessage);
fd.Flush();
fd.Close();
}
/// <summary>
/// 寫log add by Rain 做测试用
/// </summary>
/// <param name="Logmessage"></param>
public void WriteErrorLog(string Logmessage)
{
string logtime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
string logfilename = "AutoRejectServicelog" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
//string savePath =System.Web.HttpContext.Current.Server.MapPath(@"log");
//string savePath = AppDomain.CurrentDomain.BaseDirectory + @"log";
string savePath = "C:\AutoReject\log";
if (!System.IO.Directory.Exists(savePath))
{ //需要注意的是,需要对这个物理路径有足够的权限,否则会报错
//另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
System.IO.Directory.CreateDirectory(savePath);
}
Logmessage = "系統發生錯誤,發生時間:" + logtime + "
" + "錯誤信息:
" + Logmessage + "
";
System.IO.StreamWriter fd = new System.IO.StreamWriter(savePath + "\" + logfilename, true, System.Text.Encoding.Default);
fd.WriteLine(Logmessage);
fd.Flush();
fd.Close();
}