forked from xzvfinet/OneLevelJson
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLog.cs
More file actions
55 lines (49 loc) · 1.4 KB
/
Log.cs
File metadata and controls
55 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
using System.Windows.Forms;
namespace OneLevel2D
{
public class Log
{
readonly string _filePath;
public Log()
{
_filePath = @"C:\Users\Hajin\Documents\OneLevel2D\bin\Debug" + "[" + DateTime.Now.ToString("HH-mm-ss") + "]" + ".log";
try
{
var fi = new FileInfo(_filePath);
if (fi.Exists) return;
using (StreamWriter sw = new StreamWriter(_filePath))
{
sw.WriteLine("LOG START");
sw.Close();
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public string GetDateTime()
{
DateTime nowDate = DateTime.Now;
return nowDate.ToString("yyyy-MM-dd HH:mm:ss") + ":" + nowDate.Millisecond.ToString("000");
}
public void Write(string str)
{
try
{
using (StreamWriter sw = File.AppendText(_filePath))
{
string temp = string.Format("[{0}] : {1}", GetDateTime(), str);
sw.WriteLine(temp);
sw.Close();
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}