调试及发布程序时,经常需要将一些信息输出保存,这里写了一个自己的日志记录类,记录信息更方便了。需要的话还可以进行更多的扩展,比如记录异常信息等。
Modoer 是一款以本地分享,多功能的点评网站管理系统。采用 PHP+MYSQL 开发设计,开放全部源代码。因具有非凡的访问速度和卓越的负载能力而深受国内外朋友的喜爱。在升级前一定要备份好自己的原版本,特别是自己设计了模板和修改了代码的用户。Modoer多功能点评系统 v1.2.5 Build 20111220更新列表修正 安全漏洞和安全隐患增加 后台登陆和SQL错误记录日志修复 若干小BUG
using System;
using System.IO;
namespace WindowsFormsApplication1
{
public static class LogerHelper
{
#region 创建日志
///-----------------------------------------------------------------------------
/// 创建错误日志 在c:\ErrorLog\
/// 记录信息
///
///-----------------------------------------------------------------------------
public static void CreateLogTxt(string message)
{
string strPath; //文件的路径
DateTime dt = DateTime.Now;
try
{
strPath = Directory.GetCurrentDirectory() + "\\Log"; //winform工程\bin\目录下 创建日志文件夹
if(Directory.Exists(strPath)==false) //工程目录下 Log目录 '目录是否存在,为true则没有此目录
{
Directory.CreateDirectory(strPath); //建立目录 Directory为目录对象
}
strPath = strPath + "\\" + dt.ToString("yyyy");
if(Directory.Exists(strPath) == false)
{
Directory.CreateDirectory(strPath);
}
strPath = strPath + "\\" + dt.Year.ToString() + "-" + dt.Month.ToString() + ".txt";
StreamWriter FileWriter= new StreamWriter(strPath, true); //创建日志文件
FileWriter.WriteLine("[" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "] " + message);
FileWriter.Close(); //关闭StreamWriter对象
}
catch(Exception ex)
{
string str=ex.Message.ToString();
}
}
#endregion
}
}









