public static void Log(string strLogMsg, ApiLogType strLogType)
{
//設定日誌路徑
string strPath=HttpContext.Current.Server.MapPath("~/Accessary/Log/" + DateTime.Today.Year + "/" + strLogType.ToString());
//判斷路徑是否存在,若不存在,則需要創建路徑
if(!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
StreamWriter sw=null;
try
{
//創建文本
sw=File.AppendText(strPath+"\\API_"+ DateTime.Now.ToString("yyyyMMdd") +".txt");
sw.WriteLine("消息內容:"+strLogMsg);
sw.WriteLine("時間:"+DateTime.Now.Tostring("yyyy-MM-dd HH:mm:ss"));
sw.WriteLine();
}
catch{}
finally
{
if(sw!=null)
{
sw.Flush();
sw.Close();
}
}
}