using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace LogServcie
{
public static class Log
{
public static string LOGMSGPATH ="LogMsg";
public static string ERRMSGPATH = "ErrMsg";
/// <summary>
/// 用于记录用户的操作流程并记录下操作时间
/// </summary>
/// <param name="Logmsg"></param>
public static void writeLog(string Logmsg)
{
string path = System.Environment.CurrentDirectory + "//" + LOGMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//log" + DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the logfile.
sw.WriteLine(Logmsg+" "+DateTime.Now);
}
}
/// <summary>
/// 记录系统运行过程中出现的错误
/// </summary>
/// <param name="Errmsg"></param>
/// <param name="e"></param>
public static void WirteErr(string Errmsg,Exception e)
{
string path = System.Environment.CurrentDirectory + "//" + ERRMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//err"+ DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the errfile.
sw.WriteLine(Errmsg);
sw.WriteLine("出错原因: "+e.Message);
sw.Close();
}
}
/// <summary>
/// 创建制定的文档路径
/// </summary>
/// <param name="path"></param>
private static void CreaterPath(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
if (!dirInfo.Exists)
{
dirInfo.Create();
}
}
}
}