首页 > 其他 > 详细

简单日志

时间:2014-08-05 09:31:38      阅读:362      评论:0      收藏:0      [点我收藏+]

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

简单日志,布布扣,bubuko.com

简单日志

原文:http://www.cnblogs.com/lh123/p/3891482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!