标签:os io ar new log c app file
/// <summary>
/// Common 的摘要描述
/// </summary>
public class Common: System.Web.UI.Page
{
public Common()
{
//
// TODO: 在此加入建構函式的程式碼
//
}
public void Log(string userid, Exception lastError)
{
string path = Server.MapPath("~/LOG/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/LOG"));
if (!dir.Exists)
{
dir.Create();
}
FileInfo file = new FileInfo(path);
FileStream fs = null;
if (!file.Exists)
{
fs = file.Create();
fs.Dispose();
}
file = null;
StreamWriter sw = new StreamWriter(path, true);
sw.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "--" + userid + ":" + lastError.Message + "\r\n" + lastError.StackTrace);
sw.Close();
sw.Dispose();
}
}
标签:os io ar new log c app file
原文地址:http://www.cnblogs.com/lh123/p/3891482.html