using
System;
using
System.IO;
namespace
WindowsFormsApplication1
{
public
static
class
LogerHelper
{
#region 创建日志
///-----------------------------------------------------------------------------
/// <summary>创建错误日志 在c:\ErrorLog\</summary>
/// <param name="message">记录信息</param>
/// <returns></returns>
///-----------------------------------------------------------------------------
public
static
void
CreateLogTxt(
string
message)
{
string
strPath;
DateTime dt = DateTime.Now;
try
{
strPath = Directory.GetCurrentDirectory() +
"\\Log"
;
if
(Directory.Exists(strPath)==
false
)
{
Directory.CreateDirectory(strPath);
}
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();
}
catch
(Exception ex)
{
string
str=ex.Message.ToString();
}
}
#endregion
}
}