-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogMessageManager.cs
116 lines (104 loc) · 2.88 KB
/
LogMessageManager.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
public class FileWriter
{
public FileStream file = null;
public StreamWriter sw = null;
public void WriteLine(string str)
{
if (sw == null)
return;
sw.WriteLine(str);
}
public void Open(string path)
{
Close();
file = new FileStream(path, FileMode.Append, FileAccess.Write);
sw = new StreamWriter(file);
}
public void Close()
{
if (sw != null)
sw.Close();
if (file != null)
file.Close();
sw = null;
file = null;
}
public void FileLog(string str)
{
DateTime dt = DateTime.Now;
//string path = dt.ToString("yyyyMMdd");
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/ServerLog/" + dt.ToString("yyyyMMdd");
CheckCreatePath(path);
path += "/";
//path += dt.ToString("HHmm") + ".txt";
path += dt.ToString("HH") + ".txt";
Open(path);
WriteLine(dt.ToString("yyyyMMdd-HHmmss(fff) : ") + str);
Close();
}
public void RoutineDebugLog(int RoomIdx, string str)
{
DateTime dt = DateTime.Now;
//string path = dt.ToString("yyyyMMdd");
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/ServerLog/DebugRoutine/" + dt.ToString("yyyyMMdd");
CheckCreatePath(path);
path += "/";
//path += dt.ToString("HHmm") + ".txt";
path += "Room-" + RoomIdx + ".txt";
Open(path);
String log = dt.ToString("yyyyMMdd-HHmmss(fff) : ") + str;
WriteLine(log);
Debug.WriteLine(log);
Close();
}
static public void CheckCreatePath(string path)
{
DirectoryInfo di = new DirectoryInfo(path);
if (di.Exists == false)
di.Create();
}
}
class LogMessageManager
{
public static bool isDebug = false;
static object m_Lock = new object();
static List<string> m_Message = new List<string>();
static FileWriter m_FileWriter = new FileWriter();
public static void AddLogMessage(string message, bool FileLog=false)
{
lock (m_Lock)
{
m_Message.Add(message);
if (FileLog)
{
m_FileWriter.FileLog(message);
}
}
Debug.WriteLine(message);
}
public static void AddLogFile(string message)
{
lock (m_Lock)
{
m_FileWriter.FileLog(message);
}
}
public static string GetLogMessage()
{
lock (m_Lock)
{
if (m_Message.Count == 0)
return null;
string str = m_Message[0];
m_Message.RemoveAt(0);
return str;
}
}
}