当前位置: 移动技术网 > IT编程>开发语言>.net > 日志的类

日志的类

2019年07月17日  | 移动技术网IT编程  | 我要评论

却钏芘沂,情感口述实录,江民硬盘锁

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;
}
}
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网