/// <summary>
/// 写操作日志
/// </summary>
public class LogWriter
{
private static string filePath = Application.StartupPath + "\\Log";
private static bool CreateDirection(string PathName)
{
bool blnReturn = true;
try
{
if (!Directory.Exists(PathName))
{
Directory.CreateDirectory(PathName);
}
return blnReturn;
}
catch
{
return false;
}
}
public static void Write(string Info)
{
try
{
if (!CreateDirection(filePath)) return;
string strDate = DateTime.Now.ToString("yyyyMMdd");
string strDay = strDate.Substring(6,2);
string strDirectory = filePath + "\\" + strDate.Substring(0,6);
string strFileName = strDirectory + "\\" + strDay + ".txt";
if (!CreateDirection(strDirectory)) return;
if (!File.Exists(strFileName))
{
StreamWriter sr = File.CreateText(strFileName);
sr.Close();
}
StreamWriter sw = File.AppendText(strFileName);
sw.WriteLine(string.Format("发生日期:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
sw.WriteLine(Info +"\r\n");
sw.Close();
}catch
{
}
}
public static void Write(string SourceName,string Info)
{
try
{
if (!CreateDirection(filePath)) return;
string strDate = DateTime.Now.ToString("yyyyMMdd");
string strDay = strDate.Substring(6, 2);
string strDirectory = filePath + "\\" + strDate.Substring(0, 6);
string strFileName = strDirectory + "\\" + strDay + ".txt";
if (!CreateDirection(strDirectory)) return;
if (!File.Exists(strFileName))
{
StreamWriter sr = File.CreateText(strFileName);
sr.Close();
}
StreamWriter sw = File.AppendText(strFileName);
sw.WriteLine("------------------------------------");
sw.WriteLine(string.Format("函数名称:{0}", SourceName));
sw.WriteLine(string.Format("发生日期:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
sw.WriteLine(string.Format("错误信息:{0}\r\n", Info));
sw.Close();
}
catch
{
}
}
}
/// 写操作日志
/// </summary>
public class LogWriter
{
private static string filePath = Application.StartupPath + "\\Log";
private static bool CreateDirection(string PathName)
{
bool blnReturn = true;
try
{
if (!Directory.Exists(PathName))
{
Directory.CreateDirectory(PathName);
}
return blnReturn;
}
catch
{
return false;
}
}
public static void Write(string Info)
{
try
{
if (!CreateDirection(filePath)) return;
string strDate = DateTime.Now.ToString("yyyyMMdd");
string strDay = strDate.Substring(6,2);
string strDirectory = filePath + "\\" + strDate.Substring(0,6);
string strFileName = strDirectory + "\\" + strDay + ".txt";
if (!CreateDirection(strDirectory)) return;
if (!File.Exists(strFileName))
{
StreamWriter sr = File.CreateText(strFileName);
sr.Close();
}
StreamWriter sw = File.AppendText(strFileName);
sw.WriteLine(string.Format("发生日期:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
sw.WriteLine(Info +"\r\n");
sw.Close();
}catch
{
}
}
public static void Write(string SourceName,string Info)
{
try
{
if (!CreateDirection(filePath)) return;
string strDate = DateTime.Now.ToString("yyyyMMdd");
string strDay = strDate.Substring(6, 2);
string strDirectory = filePath + "\\" + strDate.Substring(0, 6);
string strFileName = strDirectory + "\\" + strDay + ".txt";
if (!CreateDirection(strDirectory)) return;
if (!File.Exists(strFileName))
{
StreamWriter sr = File.CreateText(strFileName);
sr.Close();
}
StreamWriter sw = File.AppendText(strFileName);
sw.WriteLine("------------------------------------");
sw.WriteLine(string.Format("函数名称:{0}", SourceName));
sw.WriteLine(string.Format("发生日期:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
sw.WriteLine(string.Format("错误信息:{0}\r\n", Info));
sw.Close();
}
catch
{
}
}
}