日志的类
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;
}
}
}
}