Skip to content

Commit 18b3e64

Browse files
author
ozakboy
committed
更新 備註
1 parent ccd0147 commit 18b3e64

File tree

8 files changed

+119
-31
lines changed

8 files changed

+119
-31
lines changed

ozakboy.NLOG/ozakboy.NLOG/Configurations/LogConfiguration.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,36 @@
55
namespace ozakboy.NLOG
66
{
77
/// <summary>
8-
/// LOG配置類別
8+
/// LOG配置類別 - 提供日誌系統的全局配置管理
9+
/// Log Configuration Class - Provides global configuration management for the logging system
910
/// </summary>
1011
public static class LogConfiguration
1112
{
12-
13+
/// <summary>
14+
/// 儲存當前的日誌配置選項
15+
/// Stores the current logging configuration options
16+
/// </summary>
1317
private static readonly LogOptions _currentOptions = new LogOptions();
18+
/// <summary>
19+
/// 標記日誌系統是否已經初始化
20+
/// Flag indicating whether the logging system has been initialized
21+
/// </summary>
1422
private static bool _isInitialized = false;
23+
/// <summary>
24+
/// 取得日誌系統當前的配置
25+
/// Gets the current configuration of the logging system
26+
/// </summary>
1527
public static ILogOptions Current => new ReadOnlyLogOptions(_currentOptions);
28+
/// <summary>
29+
/// 日誌配置選項介面 - 定義可供外部讀取的配置項目
30+
/// Log Options Interface - Defines configuration items available for external reading
31+
/// </summary>
1632
public interface ILogOptions
1733
{
34+
/// <summary>
35+
/// 日誌保留天數 - 定義日誌檔案的保存期限
36+
/// Log Retention Days - Defines how long log files are kept
37+
/// </summary>
1838
int KeepDays { get; }
1939
long MaxFileSize { get; }
2040
string LogPath { get; }

ozakboy.NLOG/ozakboy.NLOG/Core/AsyncLogHandler.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@
66
namespace ozakboy.NLOG.Core
77
{
88
/// <summary>
9-
/// 異步日誌處理器,負責管理日誌的異步寫入操作
9+
/// 異步日誌處理器 - 負責管理日誌的異步寫入操作,提供高效能的日誌處理機制
10+
/// Asynchronous Log Handler - Manages asynchronous log writing operations, providing high-performance logging mechanism
1011
/// </summary>
1112
internal static class AsyncLogHandler
1213
{
1314
// 核心變數
1415
/// <summary>
15-
/// 日誌隊列用於存儲待處理的日誌項目
16-
/// 使用 ConcurrentQueue 確保線程安全的入隊和出隊操作
16+
/// 日誌隊列 - 用於存儲待處理的日誌項目
17+
/// Log Queue - Stores pending log items for processing
1718
/// </summary>
19+
/// <remarks>
20+
/// 使用 ConcurrentQueue 確保線程安全的入隊和出隊操作
21+
/// Uses ConcurrentQueue to ensure thread-safe enqueue and dequeue operations
22+
/// </remarks>
1823
private static readonly ConcurrentQueue<LogItem> _logQueue = new ConcurrentQueue<LogItem>();
1924

2025
/// <summary>
21-
/// 信號量,用於通知處理線程有新的日誌需要處理
26+
/// 信號量,用於通知處理執行緒有新的日誌需要處理
2227
/// 初始計數為0,每當有新日誌加入時會釋放一個信號
28+
/// Semaphore for notifying the processing thread of new logs
29+
/// Initial count is 0, releases a signal when new logs are added
2330
/// </summary>
31+
2432
private static readonly SemaphoreSlim _signal = new SemaphoreSlim(0);
2533

2634
/// <summary>
27-
/// 取消令牌源,用於控制處理線程的生命週期
28-
/// 當需要停止處理線程時,可以通過此令牌發出取消信號
35+
/// 取消權杖來源,用於控制處理程序的生命週期
36+
/// Cancellation token source for controlling the processor lifecycle
2937
/// </summary>
3038
private static readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
3139

@@ -40,7 +48,8 @@ internal static class AsyncLogHandler
4048
private static bool _isInitialized;
4149

4250
/// <summary>
43-
/// 用於初始化同步的鎖對象
51+
/// 用於初始化同步的鎖定物件
52+
/// Lock object for initialization synchronization
4453
/// </summary>
4554
private static readonly object _lockObj = new object();
4655

@@ -51,7 +60,8 @@ private static LogConfiguration.IAsyncLogOptions CurrentAsyncOptions
5160
=> LogConfiguration.Current.AsyncOptions;
5261

5362
/// <summary>
54-
/// 上次寫入的時間
63+
/// 最後一次寫入的時間戳記
64+
/// Last write timestamp
5565
/// </summary>
5666
private static DateTime _lastFlushTime = DateTime.Now;
5767

ozakboy.NLOG/ozakboy.NLOG/Core/ExceptionHandler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
namespace ozakboy.NLOG.Core
66
{
77
/// <summary>
8-
/// 異常處理器,負責異常資訊的收集和序列化
8+
/// 異常處理器 - 負責收集和序列化異常資訊
9+
/// Exception Handler - Responsible for collecting and serializing exception information
910
/// </summary>
1011
internal static class ExceptionHandler
1112
{
1213
/// <summary>
13-
/// 用於序列化的異常資訊類別,提供異常資訊的結構化存儲
14+
/// 用於序列化的異常資訊類別 - 提供異常資訊的結構化存儲
15+
/// Serializable Exception Info Class - Provides structured storage for exception information
1416
/// </summary>
1517
public class SerializableExceptionInfo
1618
{
1719
/// <summary>
18-
/// 異常類型的完整名稱
20+
/// 異常類型的完整名稱 - 包含命名空間的類型名稱
21+
/// Full Exception Type Name - Type name with namespace
1922
/// </summary>
2023
public string Type { get; set; }
2124

2225
/// <summary>
23-
/// 異常的錯誤訊息
26+
/// 異常的錯誤訊息 - 描述錯誤的具體內容
27+
/// Exception Message - Detailed description of the error
2428
/// </summary>
2529
public string Message { get; set; }
2630

ozakboy.NLOG/ozakboy.NLOG/Core/LogFormatter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
namespace ozakboy.NLOG.Core
66
{
77
/// <summary>
8-
/// 日誌格式化處理器
8+
/// 日誌格式化處理器 - 負責將日誌內容轉換為標準格式
9+
/// Log Formatter - Responsible for converting log content into standardized format
910
/// </summary>
1011
internal static class LogFormatter
1112
{
1213
/// <summary>
13-
/// 格式化日誌訊息
14+
/// 格式化日誌訊息 - 將原始訊息轉換為包含時間戳記和執行緒 ID 的格式化訊息
15+
/// Format Log Message - Converts raw message into formatted message with timestamp and thread ID
1416
/// </summary>
17+
/// <param name="message">要格式化的訊息 / Message to format</param>
18+
/// <param name="args">格式化參數 / Formatting parameters</param>
19+
/// <returns>格式化後的訊息 / Formatted message</returns>
1520
public static string FormatMessage(string message, string[] args)
1621
{
1722
var sb = new StringBuilder();
@@ -27,8 +32,11 @@ public static string FormatMessage(string message, string[] args)
2732
}
2833

2934
/// <summary>
30-
/// 處理訊息中的特殊字符
35+
/// 處理訊息中的特殊字符 - 確保訊息中的格式化字符被正確處理
36+
/// Handle Special Characters - Ensures format characters in messages are properly handled
3137
/// </summary>
38+
/// <param name="message">原始訊息 / Original message</param>
39+
/// <returns>處理後的訊息 / Processed message</returns>
3240
public static string EscapeMessage(string message)
3341
{
3442
if (string.IsNullOrEmpty(message)) return message;

ozakboy.NLOG/ozakboy.NLOG/Core/LogItem.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,40 @@
44

55
namespace ozakboy.NLOG.Core
66
{
7+
78
/// <summary>
8-
/// 日誌項目類別,用於在不同組件間傳遞日誌資訊
9+
/// 日誌項目類別 - 用於在不同組件間傳遞日誌資訊
10+
/// Log Item Class - Used for transferring log information between different components
911
/// </summary>
1012
internal class LogItem
1113
{
1214
/// <summary>
13-
/// 日誌級別
15+
/// 日誌級別 - 定義日誌的重要程度
16+
/// Log Level - Defines the severity of the log entry
1417
/// </summary>
1518
public LogLevel Level { get; set; }
1619

1720
/// <summary>
18-
/// 日誌名稱
21+
/// 日誌名稱 - 用於識別日誌來源或類型
22+
/// Log Name - Used to identify the source or type of log
1923
/// </summary>
2024
public string Name { get; set; }
2125

2226
/// <summary>
23-
/// 日誌訊息
27+
/// 日誌訊息 - 記錄的實際內容
28+
/// Log Message - The actual content of the log entry
2429
/// </summary>
2530
public string Message { get; set; }
2631

2732
/// <summary>
28-
/// 日誌參數
33+
/// 日誌參數 - 用於格式化日誌訊息的參數陣列
34+
/// Log Parameters - Array of parameters used for formatting log messages
2935
/// </summary>
3036
public object[] Args { get; set; }
3137

3238
/// <summary>
33-
/// 是否需要立即寫入
39+
/// 是否需要立即寫入 - 控制日誌的即時性
40+
/// Immediate Flush Required - Controls whether the log needs immediate writing
3441
/// </summary>
3542
public bool RequireImmediateFlush { get; set; }
3643
}

ozakboy.NLOG/ozakboy.NLOG/Core/LogLevel.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,49 @@ namespace ozakboy.NLOG.Core
66
{
77
/// <summary>
88
/// 日誌級別
9+
/// Log Levels
910
/// </summary>
1011
public enum LogLevel
1112
{
1213
/// <summary>
13-
/// 追蹤記錄檔
14+
/// 追蹤記錄檔 - 用於追蹤程式執行的詳細流程
15+
/// Trace Log - Used for tracking detailed program execution flow
1416
/// </summary>
1517
Trace = 0,
18+
1619
/// <summary>
17-
/// 測試記錄檔
20+
/// 除錯記錄檔 - 用於開發階段的除錯訊息
21+
/// Debug Log - Used for debugging messages during development
1822
/// </summary>
1923
Debug = 1,
24+
2025
/// <summary>
21-
/// 訊息記錄檔
26+
/// 資訊記錄檔 - 記錄一般性的系統運作資訊
27+
/// Info Log - Records general system operational information
2228
/// </summary>
2329
Info = 2,
30+
2431
/// <summary>
25-
/// 警告記錄檔
32+
/// 警告記錄檔 - 記錄可能影響系統運作但不致嚴重的問題
33+
/// Warning Log - Records potential issues that might affect system operation but are not severe
2634
/// </summary>
2735
Warn = 3,
36+
2837
/// <summary>
29-
/// 錯誤記錄檔
38+
/// 錯誤記錄檔 - 記錄系統運作中的錯誤狀況
39+
/// Error Log - Records error conditions in system operation
3040
/// </summary>
3141
Error = 4,
42+
3243
/// <summary>
33-
/// 致命記錄檔
44+
/// 致命錯誤記錄檔 - 記錄導致系統無法運作的嚴重錯誤
45+
/// Fatal Log - Records severe errors that cause system failure
3446
/// </summary>
3547
Fatal = 5,
48+
3649
/// <summary>
37-
/// 自定義名稱Log記錄檔
50+
/// 自定義記錄檔 - 用於特定需求的客製化日誌類型
51+
/// Custom Log - Customized log type for specific requirements
3852
/// </summary>
3953
CostomName = 99
4054
}

ozakboy.NLOG/ozakboy.NLOG/Core/LogSerializer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ namespace ozakboy.NLOG.Core
1010
internal static class LogSerializer
1111
{
1212
// 使用傳統的初始化方式以確保跨版本兼容
13+
/// <summary>
14+
/// 預設的 JSON 序列化選項
15+
/// Default JSON serialization options
16+
/// </summary>
1317
private static readonly JsonSerializerOptions _defaultOptions;
18+
/// <summary>
19+
/// 異常序列化專用的 JSON 序列化選項
20+
/// JSON serialization options specifically for exceptions
21+
/// </summary>
1422
private static readonly JsonSerializerOptions _exceptionOptions;
1523

1624
// 在靜態建構函數中初始化

ozakboy.NLOG/ozakboy.NLOG/Core/LogText.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace ozakboy.NLOG.Core
1212
/// </summary>
1313
static class LogText
1414
{
15+
/// <summary>
16+
/// 同步鎖定物件,用於確保日誌寫入的執行緒安全
17+
/// Synchronization lock object to ensure thread-safe log writing
18+
/// </summary>
1519
private static object lockMe = new object();
1620

1721
/// <summary>
@@ -193,12 +197,25 @@ private static void Remove_TimeOutLogText()
193197
#region Class
194198

195199
/// <summary>
196-
/// 日誌檔案資訊類
200+
/// 日誌檔案資訊類別 - 用於管理單個日誌檔案的相關資訊
201+
/// Log File Information Class - Used to manage information related to a single log file
197202
/// </summary>
198203
private class LogFileInfo
199204
{
205+
/// <summary>
206+
/// 日誌檔案所在目錄的完整路徑
207+
/// Full path of the directory containing the log file
208+
/// </summary>
200209
public string DirectoryPath { get; set; }
210+
/// <summary>
211+
/// 日誌檔案的完整路徑
212+
/// Full path of the log file
213+
/// </summary>
201214
public string FilePath { get; set; }
215+
/// <summary>
216+
/// 標記是否需要建立新的日誌檔案
217+
/// Flag indicating whether a new log file needs to be created
218+
/// </summary>
202219
public bool RequiresNewFile { get; set; }
203220
}
204221

0 commit comments

Comments
 (0)