markus / KCOM / Logger.cs @ d2b05ce7
이력 | 보기 | 이력해설 | 다운로드 (2.47 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
|
8 |
namespace KCOM |
9 |
{ |
10 |
class Logger |
11 |
{ |
12 |
|
13 |
public static void sendReqLog(string name, string text, int Loglevel) |
14 |
{ |
15 |
try |
16 |
{ |
17 |
int lv = global::KCOM.Properties.Settings.Default.loglevel; |
18 |
if (lv >= Loglevel) //세팅의 로그 레벨보다 낮거나 같으면 남김 |
19 |
{ |
20 |
// string Msg = (string)text + " / " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
21 |
string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + "REQ" + "\t" + name + "(" + (string)text + ")" + "\r\n"; |
22 |
string Dir = AppDomain.CurrentDomain.BaseDirectory + "Log"; |
23 |
|
24 |
if (Directory.Exists(Dir) == false) |
25 |
{ |
26 |
Directory.CreateDirectory(Dir); |
27 |
} |
28 |
|
29 |
int min = DateTime.Now.Minute / 1; |
30 |
|
31 |
string path = Dir + "/" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd HH-") + min + ".txt"; |
32 |
File.AppendAllText(path, Msg); |
33 |
} |
34 |
} |
35 |
catch (Exception e) |
36 |
{ |
37 |
Debug.WriteLine(e); |
38 |
} |
39 |
} |
40 |
|
41 |
public static void sendResLog(string name, string text, int Loglevel) |
42 |
{ |
43 |
try |
44 |
{ |
45 |
int lv = global::KCOM.Properties.Settings.Default.loglevel; |
46 |
if (lv >= Loglevel) //세팅의 로그 레벨보다 낮거나 같으면 남김 |
47 |
{ |
48 |
// string Msg = (string)text + " / " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
49 |
string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + "RES" + "\t" + name + "(" + (string)text + ")" + "\r\n"; |
50 |
string Dir = AppDomain.CurrentDomain.BaseDirectory + "Log"; |
51 |
|
52 |
if (Directory.Exists(Dir) == false) |
53 |
{ |
54 |
Directory.CreateDirectory(Dir); |
55 |
} |
56 |
|
57 |
int min = DateTime.Now.Minute / 1; |
58 |
|
59 |
string path = Dir + "/" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd HH-") + min + ".txt"; |
60 |
File.AppendAllText(path, Msg); |
61 |
} |
62 |
} |
63 |
catch (Exception e) |
64 |
{ |
65 |
Debug.WriteLine(e); |
66 |
} |
67 |
} |
68 |
} |
69 |
} |