Skip to content

Commit dd0492e

Browse files
committed
docs(logger): 为 Logger 项目添加双语文档注释
为 LogHelper 及其部分类、LogHandler、LogOptions 和 InternalTempLogger 添加标准的双语文档注释(中文 + 英文),遵循项目文档规范: - summary 使用中文描述 - remarks 包含英文翻译 - param/returns/typeparam 使用双语格式
1 parent 81ff20c commit dd0492e

11 files changed

Lines changed: 1093 additions & 972 deletions

GameFrameX.Foundation.Logger/Internal/InternalTempLogger.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,44 @@
3838

3939
namespace GameFrameX.Foundation.Logger.Internal;
4040

41+
/// <summary>
42+
/// 内部临时日志记录器,用于在日志系统初始化前临时存储日志事件。
43+
/// </summary>
44+
/// <remarks>
45+
/// This class provides a temporary logger that buffers log events before the main logging system is initialized.
46+
/// It allows log messages to be captured early in the application lifecycle and then flushed to the main logger once available.
47+
/// </remarks>
4148
internal sealed class InternalTempLogger : IDisposable
4249
{
4350
private readonly ILogger _logger;
4451
private readonly LoggerMemorySink _buffer;
4552
private bool _isFlushed;
4653
private bool _isDisposed;
4754

55+
/// <summary>
56+
/// 获取日志记录器实例。 / Gets the logger instance.
57+
/// </summary>
58+
/// <value>The ILogger instance.</value>
4859
public ILogger Logger
4960
{
5061
get { return _logger; }
5162
}
5263

64+
/// <summary>
65+
/// 获取日志内存缓冲区。 / Gets the log memory buffer.
66+
/// </summary>
67+
/// <value>The LoggerMemorySink instance.</value>
5368
public LoggerMemorySink Buffer
5469
{
5570
get { return _buffer; }
5671
}
5772

73+
/// <summary>
74+
/// 初始化内部临时日志记录器的新实例。
75+
/// </summary>
76+
/// <remarks>
77+
/// Creates a new internal temporary logger with a memory sink that captures all log events at verbose level.
78+
/// </remarks>
5879
public InternalTempLogger()
5980
{
6081
_buffer = new LoggerMemorySink(OnLogEvent);
@@ -64,11 +85,23 @@ public InternalTempLogger()
6485
.CreateLogger();
6586
}
6687

88+
/// <summary>
89+
/// 处理日志事件的回调方法。 / Callback method for handling log events.
90+
/// </summary>
91+
/// <param name="evt">日志事件 / The log event</param>
6792
private void OnLogEvent(LogEvent evt)
6893
{
6994
Console.WriteLine(evt.RenderMessage());
7095
}
7196

97+
/// <summary>
98+
/// 将缓冲的日志事件刷新到目标日志记录器。
99+
/// </summary>
100+
/// <param name="targetLogger">目标日志记录器实例 / The target logger instance</param>
101+
/// <remarks>
102+
/// Writes all buffered log events to the target logger. This method can only be called once;
103+
/// subsequent calls will be ignored. Also ignores calls if the logger has been disposed.
104+
/// </remarks>
72105
public void FlushTo(ILogger targetLogger)
73106
{
74107
if (_isFlushed || _isDisposed)
@@ -84,6 +117,13 @@ public void FlushTo(ILogger targetLogger)
84117
_isFlushed = true;
85118
}
86119

120+
/// <summary>
121+
/// 释放临时日志记录器使用的资源。
122+
/// </summary>
123+
/// <remarks>
124+
/// Disposes the internal logger if it implements IDisposable. This method can only be called once;
125+
/// subsequent calls will be ignored.
126+
/// </remarks>
87127
public void Dispose()
88128
{
89129
if (_isDisposed)
@@ -98,4 +138,4 @@ public void Dispose()
98138

99139
_isDisposed = true;
100140
}
101-
}
141+
}

GameFrameX.Foundation.Logger/LogHandler.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ namespace GameFrameX.Foundation.Logger;
4343
/// <summary>
4444
/// 日志处理器类,提供日志系统的初始化和配置功能
4545
/// </summary>
46+
/// <remarks>
47+
/// Provides initialization and configuration functionality for the logging system.
48+
/// </remarks>
4649
public static class LogHandler
4750
{
4851
private static bool _isInitSerilogDiagnosis;
4952

5053
/// <summary>
5154
/// 启用 Serilog 的自动诊断
5255
/// </summary>
56+
/// <remarks>
57+
/// Enables Serilog's automatic diagnosis for debugging purposes.
58+
/// </remarks>
5359
private static void SerilogDiagnosis()
5460
{
5561
if (_isInitSerilogDiagnosis)
@@ -64,12 +70,12 @@ private static void SerilogDiagnosis()
6470
/// <summary>
6571
/// 创建并返回一个基础的 Serilog 日志配置。
6672
/// </summary>
73+
/// <returns>用于后续扩展的基础 LoggerConfiguration / The base LoggerConfiguration for subsequent extension</returns>
6774
/// <remarks>
68-
/// - 启用上下文丰富(Enrich.FromLogContext),便于在日志中附带请求或业务上下文信息。
69-
/// - 下调框架日志噪声:将 Microsoft 组件日志级别设为 Information,将 ASP.NET Core 设为 Warning,减少不必要的输出。
70-
/// 该基础配置可在后续继续追加写入目标、丰富属性、最小日志级别等。
75+
/// <para>- Enables context enrichment (Enrich.FromLogContext) to easily attach request or business context information to logs.</para>
76+
/// <para>- Reduces framework log noise: sets Microsoft component log level to Information, ASP.NET Core to Warning, reducing unnecessary output.</para>
77+
/// <para>This base configuration can be extended with additional write targets, enrichment properties, minimum log levels, etc.</para>
7178
/// </remarks>
72-
/// <returns>用于后续扩展的基础 LoggerConfiguration。</returns>
7379
public static LoggerConfiguration CreateLoggerConfiguration()
7480
{
7581
return new LoggerConfiguration()
@@ -82,39 +88,40 @@ public static LoggerConfiguration CreateLoggerConfiguration()
8288
}
8389

8490
/// <summary>
85-
/// 控制台输出模板,用于格式化控制台日志输出。
91+
/// 控制台输出模板,用于格式化控制台日志输出。 / Console output template for formatting console log output.
8692
/// </summary>
8793
private const string ConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}][{LogType}]{Message:lj}{NewLine}{Exception}";
8894

8995
/// <summary>
90-
/// 控制台输出模板,用于格式化控制台日志输出,包含标签名称。
96+
/// 控制台输出模板,用于格式化控制台日志输出,包含标签名称。 / Console output template for formatting console log output with tag name.
9197
/// </summary>
9298
private const string ConsoleOutputTagNameTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}][{LogType}-{TagName}]{Message:lj}{NewLine}{Exception}";
9399

94100
/// <summary>
95-
/// 文件输出模板,用于格式化文件日志输出。
101+
/// 文件输出模板,用于格式化文件日志输出。 / File output template for formatting file log output.
96102
/// </summary>
97103
private const string FileOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}][{LogType}]{Message:lj}{NewLine}{Exception}";
98104

99105
/// <summary>
100-
/// 文件输出模板,用于格式化文件日志输出,包含标签名称。
106+
/// 文件输出模板,用于格式化文件日志输出,包含标签名称。 / File output template for formatting file log output with tag name.
101107
/// </summary>
102108
private const string FileOutputTagNameTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}][{LogType}-{TagName}]{Message:lj}{NewLine}{Exception}";
103109

104110
/// <summary>
105111
/// 启动并配置日志系统。
106112
/// </summary>
107-
/// <param name="logOptions">日志配置选项,包含日志级别、存储路径等配置信息。</param>
108-
/// <param name="isDefault">是否设置为默认配置。</param>
109-
/// <param name="configurationAction">自定义日志配置回调。</param>
110-
/// <exception cref="ArgumentNullException">当 <paramref name="logOptions"/> 参数为 null 时抛出。</exception>
111-
/// <exception cref="ArgumentException">当 <paramref name="logOptions.LogTagName"/> 为空或仅包含空白字符时抛出。</exception>
112-
/// <exception cref="DirectoryNotFoundException">日志文件目录不存在且无法创建时抛出。</exception>
113-
/// <exception cref="UnauthorizedAccessException">没有权限创建日志目录或写入日志文件时抛出。</exception>
114-
/// <exception cref="Exception">初始化日志系统过程中发生的其他异常。</exception>
113+
/// <param name="logOptions">日志配置选项,包含日志级别、存储路径等配置信息 / Log configuration options containing log level, storage path, and other configuration information</param>
114+
/// <param name="isDefault">是否设置为默认配置 / Whether to set as default configuration</param>
115+
/// <param name="configurationAction">自定义日志配置回调 / Custom log configuration callback</param>
116+
/// <exception cref="ArgumentNullException">当 <paramref name="logOptions"/> 参数为 null 时抛出 / Thrown when <paramref name="logOptions"/> parameter is null</exception>
117+
/// <exception cref="ArgumentException">当 <paramref name="logOptions.LogTagName"/> 为空或仅包含空白字符时抛出 / Thrown when <paramref name="logOptions.LogTagName"/> is empty or contains only whitespace</exception>
118+
/// <exception cref="DirectoryNotFoundException">日志文件目录不存在且无法创建时抛出 / Thrown when log file directory does not exist and cannot be created</exception>
119+
/// <exception cref="UnauthorizedAccessException">没有权限创建日志目录或写入日志文件时抛出 / Thrown when there is no permission to create log directory or write log files</exception>
120+
/// <exception cref="Exception">初始化日志系统过程中发生的其他异常 / Other exceptions that occur during log system initialization</exception>
121+
/// <returns>配置好的 ILogger 实例 / The configured ILogger instance</returns>
115122
/// <remarks>
116-
/// <para>该方法会根据传入的 <paramref name="logOptions"/> 配置初始化日志系统,支持文件、控制台、MongoDB Grafana Loki 等多种输出方式。</para>
117-
/// <para>异常类型涵盖参数校验、目录创建、权限不足及日志系统初始化过程中的所有可能异常。</para>
123+
/// <para>This method initializes the logging system based on the provided <paramref name="logOptions"/> configuration, supporting multiple output methods such as file, console, MongoDB, and Grafana Loki.</para>
124+
/// <para>The exception types cover parameter validation, directory creation, insufficient permissions, and all possible exceptions during log system initialization.</para>
118125
/// </remarks>
119126
/// <example>
120127
/// <code>

GameFrameX.Foundation.Logger/LogHelper.Console.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ namespace GameFrameX.Foundation.Logger;
3737
/// 日志帮助类的控制台显示部分
3838
/// </summary>
3939
/// <remarks>
40-
/// 提供了一系列静态方法用于在控制台中显示格式化的标题、配置信息和分隔线。
41-
/// 这是LogHelper类的部分类实现,专门处理控制台输出相关功能。
40+
/// Provides a series of static methods for displaying formatted titles, configuration information, and separators in the console.
41+
/// This is a partial class implementation of LogHelper, specifically handling console output related functionality.
4242
/// </remarks>
4343
public partial class LogHelper
4444
{
4545
/// <summary>
46-
/// 控制台日志显示对象实例,用于处理所有控制台格式化输出
46+
/// 控制台日志显示对象实例,用于处理所有控制台格式化输出 / Console log display object instance for handling all console formatted output
4747
/// </summary>
4848
private static readonly LogConsole LogConsoleObject = new();
4949

5050
/// <summary>
5151
/// 设置控制台输出框架的宽度
5252
/// </summary>
53-
/// <param name="length">框架宽度,必须大于0的整数值</param>
54-
/// <exception cref="ArgumentOutOfRangeException">当length小于等于0时抛出</exception>
53+
/// <param name="length">框架宽度,必须大于0的整数值 / The frame width, must be an integer greater than 0</param>
54+
/// <exception cref="ArgumentOutOfRangeException">当 <paramref name="length"/> 小于等于0时抛出 / Thrown when <paramref name="length"/> is less than or equal to 0</exception>
5555
/// <remarks>
56-
/// 此设置会影响所有后续的控制台输出格式,包括标题框、配置信息框和分隔线的宽度。
56+
/// This setting affects the width of all subsequent console output formats, including title boxes, configuration information boxes, and separator lines.
5757
/// </remarks>
5858
public static void SetFrameLength(int length)
5959
{
@@ -64,13 +64,13 @@ public static void SetFrameLength(int length)
6464
/// <summary>
6565
/// 显示带边框的大标题,支持主标题和最多两个子标题
6666
/// </summary>
67-
/// <param name="title">主标题文本,不能为null</param>
68-
/// <param name="title2">第一个子标题文本,可选参数</param>
69-
/// <param name="title3">第二个子标题文本,可选参数</param>
70-
/// <exception cref="ArgumentNullException">当任何参数为null时抛出</exception>
67+
/// <param name="title">主标题文本,不能为null / The main title text, cannot be null</param>
68+
/// <param name="title2">第一个子标题文本,可选参数 / The first subtitle text, optional parameter</param>
69+
/// <param name="title3">第二个子标题文本,可选参数 / The second subtitle text, optional parameter</param>
70+
/// <exception cref="ArgumentNullException">当任何参数为null时抛出 / Thrown when any parameter is null</exception>
7171
/// <remarks>
72-
/// 使用双线框字符(╔╗╚╝║)创建美观的标题显示效果。
73-
/// 子标题只有在非空时才会显示,标题文本会自动居中对齐。
72+
/// Uses double-line box characters (╔╗╚╝║) to create a beautiful title display effect.
73+
/// Subtitles are only displayed when non-empty, and title text is automatically center-aligned.
7474
/// </remarks>
7575
public static void ShowMaxTitle(string title, string title2 = "", string title3 = "")
7676
{
@@ -83,12 +83,12 @@ public static void ShowMaxTitle(string title, string title2 = "", string title3
8383
/// <summary>
8484
/// 显示带标题的配置信息框
8585
/// </summary>
86-
/// <param name="title">配置项标题,不能为null</param>
87-
/// <param name="content">配置内容对象,将调用ToString()方法显示,不能为null</param>
88-
/// <exception cref="ArgumentNullException">当任何参数为null时抛出</exception>
86+
/// <param name="title">配置项标题,不能为null / The configuration item title, cannot be null</param>
87+
/// <param name="content">配置内容对象,将调用ToString()方法显示,不能为null / The configuration content object, will call ToString() method to display, cannot be null</param>
88+
/// <exception cref="ArgumentNullException">当任何参数为null时抛出 / Thrown when any parameter is null</exception>
8989
/// <remarks>
90-
/// 创建一个带有标题栏的信息框,标题会嵌入到顶部边框中,内容显示在框内。
91-
/// 适用于显示系统配置、参数设置等结构化信息。
90+
/// Creates an information box with a title bar, where the title is embedded in the top border and the content is displayed inside the box.
91+
/// Suitable for displaying system configuration, parameter settings, and other structured information.
9292
/// </remarks>
9393
public static void ShowOption(string title, object content)
9494
{
@@ -100,12 +100,12 @@ public static void ShowOption(string title, object content)
100100
/// <summary>
101101
/// 显示分隔线,可选择是否包含标题文本
102102
/// </summary>
103-
/// <param name="title">分隔线中的标题文本,为空字符串时显示纯分隔线</param>
104-
/// <exception cref="ArgumentNullException">当title为null时抛出</exception>
103+
/// <param name="title">分隔线中的标题文本,为空字符串时显示纯分隔线 / The title text in the separator line, displays a pure separator line when empty</param>
104+
/// <exception cref="ArgumentNullException">当 <paramref name="title"/> 为null时抛出 / Thrown when <paramref name="title"/> is null</exception>
105105
/// <remarks>
106-
/// 当title为空时,显示纯分隔线;当title有内容时,标题会嵌入到分隔线中间。
107-
/// 如果标题过长超出框架宽度,会使用简化的三等号包围格式。
108-
/// 常用于分隔不同的信息区块或标记程序执行的不同阶段。
106+
/// When title is empty, displays a pure separator line; when title has content, the title is embedded in the middle of the separator line.
107+
/// If the title is too long and exceeds the frame width, a simplified triple-equals enclosing format is used.
108+
/// Commonly used to separate different information blocks or mark different stages of program execution.
109109
/// </remarks>
110110
public static void ShowLineTitle(string title = "")
111111
{

0 commit comments

Comments
 (0)