Skip to content

Commit 3687934

Browse files
author
ozakboy
committed
新增 可以不寫 txt 純寫 Console log
1 parent 3d900cd commit 3687934

File tree

2 files changed

+85
-23
lines changed

2 files changed

+85
-23
lines changed

Diff for: ozakboy.NLOG/ozakboy.NLOG.Test/Program.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
Console.WriteLine("Hello, World!");
33
LOG.SetLogKeepDay(-7);
44
LOG.Trace_Log("LOG_TEST");
5-
LOG.Info_Log("LOG_TEST");
5+
LOG.Info_Log("LOG_TEST", false);
66
LOG.Debug_Log("LOG_TEST");
77
LOG.Error_Log("LOG_TEST");
88
LOG.Warn_Log("LOG_TEST");
99
LOG.Fatal_Log("LOG_TEST");
1010
LOG.CostomName_Log("ABC", "LOG_TEST");
1111

12-
for (int i = 0; i < 1000000; i++)
13-
{
14-
LOG.CostomName_Log("BigFile_1", "LOG_TEST");
15-
}
12+
//for (int i = 0; i < 1000000; i++)
13+
//{
14+
// LOG.CostomName_Log("BigFile_1", "LOG_TEST");
15+
//}
1616

1717
try
1818
{

Diff for: ozakboy.NLOG/ozakboy.NLOG/NLOG.cs

+80-18
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,32 @@ public static class LOG
1717
/// 追蹤記錄檔
1818
/// </summary>
1919
/// <param name="Message"></param>
20+
/// <param name="WriteTxt"></param>
2021
/// <param name="arg"></param>
21-
public static void Trace_Log(string Message, string[] arg)
22+
public static void Trace_Log(string Message, bool WriteTxt, string[] arg )
2223
{
2324
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
2425
Console.WriteLine(Message, arg);
25-
LogText.Add_LogText("Trace", Message, arg);
26+
if(WriteTxt)
27+
LogText.Add_LogText("Trace", Message, arg);
2628
}
2729
/// <summary>
2830
/// 追蹤記錄檔
2931
/// </summary>
3032
/// <param name="Message"></param>
3133
public static void Trace_Log(string Message)
3234
{
33-
Trace_Log(Message, new string[0]);
35+
Trace_Log(Message, true, new string[0]);
36+
}
37+
38+
/// <summary>
39+
/// 追蹤記錄檔
40+
/// </summary>
41+
/// <param name="Message"></param>
42+
/// <param name="WriteTxt"></param>
43+
public static void Trace_Log(string Message, bool WriteTxt)
44+
{
45+
Trace_Log(Message, WriteTxt, new string[0]);
3446
}
3547

3648
#endregion
@@ -42,11 +54,12 @@ public static void Trace_Log(string Message)
4254
/// </summary>
4355
/// <param name="Message">訊息</param>
4456
/// <param name="arg">正規化文字</param>
45-
public static void Debug_Log(string Message, string[] arg)
57+
public static void Debug_Log(string Message, bool WriteTxt, string[] arg)
4658
{
4759
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
4860
Console.WriteLine(Message, arg);
49-
LogText.Add_LogText("Debug", Message, arg);
61+
if(WriteTxt)
62+
LogText.Add_LogText("Debug", Message, arg);
5063
}
5164

5265
/// <summary>
@@ -55,7 +68,15 @@ public static void Debug_Log(string Message, string[] arg)
5568
/// <param name="Message">訊息</param>
5669
public static void Debug_Log(string Message)
5770
{
58-
Debug_Log(Message, new string[0]);
71+
Debug_Log(Message , true, new string[0]);
72+
}
73+
/// <summary>
74+
/// 測試記錄檔
75+
/// </summary>
76+
/// <param name="Message">訊息</param>
77+
public static void Debug_Log(string Message, bool WriteTxt)
78+
{
79+
Debug_Log(Message, WriteTxt, new string[0]);
5980
}
6081

6182
#endregion
@@ -68,11 +89,12 @@ public static void Debug_Log(string Message)
6889
/// </summary>
6990
/// <param name="Message">訊息</param>
7091
/// <param name="arg">正規化文字</param>
71-
public static void Info_Log(string Message, string[] arg)
92+
public static void Info_Log(string Message, bool WriteTxt, string[] arg)
7293
{
7394
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
7495
Console.WriteLine(Message, arg);
75-
LogText.Add_LogText("Info", Message, arg);
96+
if(WriteTxt)
97+
LogText.Add_LogText("Info", Message, arg);
7698
}
7799

78100
/// <summary>
@@ -81,7 +103,16 @@ public static void Info_Log(string Message, string[] arg)
81103
/// <param name="Message">訊息</param>
82104
public static void Info_Log(string Message)
83105
{
84-
Info_Log(Message, new string[0]);
106+
Info_Log(Message,true, new string[0]);
107+
}
108+
109+
/// <summary>
110+
/// 訊息記錄檔
111+
/// </summary>
112+
/// <param name="Message">訊息</param>
113+
public static void Info_Log(string Message, bool WriteTxt)
114+
{
115+
Info_Log(Message, WriteTxt, new string[0]);
85116
}
86117

87118

@@ -94,11 +125,12 @@ public static void Info_Log(string Message)
94125
/// </summary>
95126
/// <param name="Message">訊息</param>
96127
/// <param name="arg">正規化文字</param>
97-
public static void Warn_Log(string Message, string[] arg)
128+
public static void Warn_Log(string Message, bool WriteTxt, string[] arg)
98129
{
99130
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
100131
Console.WriteLine(Message, arg);
101-
LogText.Add_LogText("Warn", Message, arg);
132+
if(WriteTxt)
133+
LogText.Add_LogText("Warn", Message, arg);
102134
}
103135

104136
/// <summary>
@@ -107,7 +139,16 @@ public static void Warn_Log(string Message, string[] arg)
107139
/// <param name="Message">訊息</param>
108140
public static void Warn_Log(string Message)
109141
{
110-
Warn_Log(Message, new string[0]);
142+
Warn_Log(Message, true, new string[0]);
143+
}
144+
145+
/// <summary>
146+
/// 警告記錄檔
147+
/// </summary>
148+
/// <param name="Message">訊息</param>
149+
public static void Warn_Log(string Message, bool WriteTxt)
150+
{
151+
Warn_Log(Message, WriteTxt, new string[0]);
111152
}
112153

113154
/// <summary>
@@ -179,11 +220,12 @@ private static void GetExceptionMessage(Exception ex, ref String Message)
179220
/// </summary>
180221
/// <param name="Message">訊息</param>
181222
/// <param name="arg">正規化文字</param>
182-
public static void Error_Log(string Message, string[] arg)
223+
public static void Error_Log(string Message, bool WriteTxt, string[] arg)
183224
{
184225
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
185226
Console.WriteLine(Message, arg);
186-
LogText.Add_LogText("Error", Message, arg);
227+
if(WriteTxt)
228+
LogText.Add_LogText("Error", Message, arg);
187229
}
188230

189231
/// <summary>
@@ -192,7 +234,16 @@ public static void Error_Log(string Message, string[] arg)
192234
/// <param name="Message">訊息</param>
193235
public static void Error_Log(string Message)
194236
{
195-
Error_Log(Message, new string[0]);
237+
Error_Log(Message,true, new string[0]);
238+
}
239+
240+
/// <summary>
241+
/// 錯誤紀錄檔
242+
/// </summary>
243+
/// <param name="Message">訊息</param>
244+
public static void Error_Log(string Message, bool WriteTxt)
245+
{
246+
Error_Log(Message, WriteTxt, new string[0]);
196247
}
197248

198249
#endregion
@@ -228,11 +279,12 @@ public static void Fatal_Log(string Message)
228279
/// <param name="Custom">自定義名稱</param>
229280
/// <param name="Message">訊息</param>
230281
/// <param name="arg">正規化文字</param>
231-
public static void CostomName_Log(string Custom, string Message, string[] arg)
282+
public static void CostomName_Log(string Custom, string Message, bool WriteTxt, string[] arg)
232283
{
233284
Message = $"{DateTime.Now.ToString("HH:mm:ss")}[{Thread.CurrentThread.ManagedThreadId}] {Message}";
234285
Console.WriteLine(Message, arg);
235-
LogText.Add_LogText(Custom, Message, arg);
286+
if(WriteTxt)
287+
LogText.Add_LogText(Custom, Message, arg);
236288
}
237289

238290
/// <summary>
@@ -242,7 +294,17 @@ public static void CostomName_Log(string Custom, string Message, string[] arg)
242294
/// <param name="Message">訊息</param>
243295
public static void CostomName_Log(string Custom, string Message)
244296
{
245-
CostomName_Log(Custom, Message, new string[0]);
297+
CostomName_Log(Custom, Message , true, new string[0]);
298+
}
299+
300+
/// <summary>
301+
/// 自定義名稱Log記錄檔
302+
/// </summary>
303+
/// <param name="Custom">自定義名稱</param>
304+
/// <param name="Message">訊息</param>
305+
public static void CostomName_Log(string Custom, string Message, bool WriteTxt)
306+
{
307+
CostomName_Log(Custom, Message, WriteTxt, new string[0]);
246308
}
247309

248310
/// <summary>

0 commit comments

Comments
 (0)