public static class LogHelper { private static string strLogFolder; private static string strLogFile; private static object _obj = new object(); publi ...
public static class LogHelper
{
private static string strLogFolder;
private static string strLogFile;
private static object _obj = new object();
public static void CreatFile()
{
lock (_obj)
{
try
{
strLogFolder = Directory.GetCurrentDirectory() + "\\Log";
if (!Directory.Exists(strLogFolder))
{
Directory.CreateDirectory(strLogFolder);
}
strLogFile = strLogFolder + "\\" + DateTime.Now.ToString("yy-MM-dd")+".Log";
if (!File.Exists(strLogFile))
{
File.Create(strLogFile);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
public static void WriteMessage(string msg)
{
lock(_obj)
{
try
{
strLogFile = strLogFolder + "\\" + DateTime.Now.ToString("yy-MM-dd") + ".Log";
if (!File.Exists(strLogFile))
{
File.Create(strLogFile);
}
using (StreamWriter sw = new StreamWriter(strLogFile, true, Encoding.UTF8))
{
sw.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + msg + "\r\n");
}
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}