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();
}
}
}