public static string GetDateTime()
{
DateTime NowDate = DateTime.Now;
return NowDate.ToString("yyyy-MM-dd HH:mm:ss") + ":" + NowDate.Millisecond.ToString("000");
}
public static void func_Log(String msg)
{
string FilePath = Directory.GetCurrentDirectory() + @"\Logs\" + DateTime.Today.ToString("yyyyMMdd") + ".log";
string DirPath = Directory.GetCurrentDirectory() + @"\Logs";
string temp;
DirectoryInfo di = new DirectoryInfo(DirPath);
FileInfo fi = new FileInfo(FilePath);
try
{
if (di.Exists != true) Directory.CreateDirectory(DirPath);
if (fi.Exists != true)
{
using (StreamWriter sw = new StreamWriter(FilePath))
{
temp = string.Format("[{0}] {1}", GetDateTime(), msg);
sw.WriteLine(temp);
sw.Close();
}
}
else
{
using (StreamWriter sw = File.AppendText(FilePath))
{
temp = string.Format("[{0}] {1}", GetDateTime(), msg);
sw.WriteLine(temp);
sw.Close();
}
}
}
catch (Exception e)
{
Debug.Log("error :"+e.ToString());
}
}
댓글 없음:
댓글 쓰기