From 3b71aa6fd26078ac65cfb1c4a70d9bf13d7d5b2e Mon Sep 17 00:00:00 2001 From: walterlv Date: Thu, 12 Sep 2024 10:19:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=B0=E6=97=A5=E5=BF=97=E7=BA=A7?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Logger/LogLevel.g.cs | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/dotnetCampus.Logger/LogLevel.g.cs b/src/dotnetCampus.Logger/LogLevel.g.cs index 9a46a7a..119615a 100644 --- a/src/dotnetCampus.Logger/LogLevel.g.cs +++ b/src/dotnetCampus.Logger/LogLevel.g.cs @@ -42,3 +42,53 @@ public enum LogLevel /// None = 6, } + +/// +/// 辅助将字符串解析为日志级别。 +/// +public static class LogLevelParser +{ + /// + /// 尝试解析字符串为日志级别,支持常用的日志级别别名,大小写不敏感。 + /// + /// 要解析的字符串。 + /// 日志级别。 + /// + /// 目前已支持的别名有: + /// + /// 追踪级:0, trace, tracing + /// 调试级:1, debug, debugging + /// 一般级:2, info, information + /// 警告级:3, warn, warning + /// 错误级:4, err, error + /// 崩溃级:5, critical, fatal + /// 无日志:6, no, none + /// + /// 其他所有字符串均返回 。 + /// + public static LogLevel? Parse(string text) => text.ToLowerInvariant() switch + { + "trace" => LogLevel.Trace, + "tracing" => LogLevel.Trace, + "debug" => LogLevel.Debug, + "debugging" => LogLevel.Debug, + "info" => LogLevel.Information, + "information" => LogLevel.Information, + "warn" => LogLevel.Warning, + "warning" => LogLevel.Warning, + "err" => LogLevel.Error, + "error" => LogLevel.Error, + "critical" => LogLevel.Critical, + "fatal" => LogLevel.Critical, + "no" => LogLevel.None, + "none" => LogLevel.None, + "0" => LogLevel.Trace, + "1" => LogLevel.Debug, + "2" => LogLevel.Information, + "3" => LogLevel.Warning, + "4" => LogLevel.Error, + "5" => LogLevel.Critical, + "6" => LogLevel.None, + _ => null, + }; +} From 62db9ab2d5bee27b2558616a5d5041ce3f5ca2c9 Mon Sep 17 00:00:00 2001 From: walterlv Date: Thu, 12 Sep 2024 10:24:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Parser=20=E5=9C=A8=E6=BA=90=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E4=B8=AD=E4=B8=8D=E5=BA=94=E5=87=BA=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Logger/LogLevel.g.cs | 50 ---------------------- src/dotnetCampus.Logger/LogLevelParser.cs | 51 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 src/dotnetCampus.Logger/LogLevelParser.cs diff --git a/src/dotnetCampus.Logger/LogLevel.g.cs b/src/dotnetCampus.Logger/LogLevel.g.cs index 119615a..9a46a7a 100644 --- a/src/dotnetCampus.Logger/LogLevel.g.cs +++ b/src/dotnetCampus.Logger/LogLevel.g.cs @@ -42,53 +42,3 @@ public enum LogLevel /// None = 6, } - -/// -/// 辅助将字符串解析为日志级别。 -/// -public static class LogLevelParser -{ - /// - /// 尝试解析字符串为日志级别,支持常用的日志级别别名,大小写不敏感。 - /// - /// 要解析的字符串。 - /// 日志级别。 - /// - /// 目前已支持的别名有: - /// - /// 追踪级:0, trace, tracing - /// 调试级:1, debug, debugging - /// 一般级:2, info, information - /// 警告级:3, warn, warning - /// 错误级:4, err, error - /// 崩溃级:5, critical, fatal - /// 无日志:6, no, none - /// - /// 其他所有字符串均返回 。 - /// - public static LogLevel? Parse(string text) => text.ToLowerInvariant() switch - { - "trace" => LogLevel.Trace, - "tracing" => LogLevel.Trace, - "debug" => LogLevel.Debug, - "debugging" => LogLevel.Debug, - "info" => LogLevel.Information, - "information" => LogLevel.Information, - "warn" => LogLevel.Warning, - "warning" => LogLevel.Warning, - "err" => LogLevel.Error, - "error" => LogLevel.Error, - "critical" => LogLevel.Critical, - "fatal" => LogLevel.Critical, - "no" => LogLevel.None, - "none" => LogLevel.None, - "0" => LogLevel.Trace, - "1" => LogLevel.Debug, - "2" => LogLevel.Information, - "3" => LogLevel.Warning, - "4" => LogLevel.Error, - "5" => LogLevel.Critical, - "6" => LogLevel.None, - _ => null, - }; -} diff --git a/src/dotnetCampus.Logger/LogLevelParser.cs b/src/dotnetCampus.Logger/LogLevelParser.cs new file mode 100644 index 0000000..fc3cdc3 --- /dev/null +++ b/src/dotnetCampus.Logger/LogLevelParser.cs @@ -0,0 +1,51 @@ +namespace dotnetCampus.Logging; + +/// +/// 辅助将字符串解析为日志级别。 +/// +public static class LogLevelParser +{ + /// + /// 尝试解析字符串为日志级别,支持常用的日志级别别名,大小写不敏感。 + /// + /// 要解析的字符串。 + /// 日志级别。 + /// + /// 目前已支持的别名有: + /// + /// 追踪级:0, trace, tracing + /// 调试级:1, debug, debugging + /// 一般级:2, info, information + /// 警告级:3, warn, warning + /// 错误级:4, err, error + /// 崩溃级:5, critical, fatal + /// 无日志:6, no, none + /// + /// 其他所有字符串均返回 。 + /// + public static LogLevel? Parse(string text) => text.ToLowerInvariant() switch + { + "trace" => LogLevel.Trace, + "tracing" => LogLevel.Trace, + "debug" => LogLevel.Debug, + "debugging" => LogLevel.Debug, + "info" => LogLevel.Information, + "information" => LogLevel.Information, + "warn" => LogLevel.Warning, + "warning" => LogLevel.Warning, + "err" => LogLevel.Error, + "error" => LogLevel.Error, + "critical" => LogLevel.Critical, + "fatal" => LogLevel.Critical, + "no" => LogLevel.None, + "none" => LogLevel.None, + "0" => LogLevel.Trace, + "1" => LogLevel.Debug, + "2" => LogLevel.Information, + "3" => LogLevel.Warning, + "4" => LogLevel.Error, + "5" => LogLevel.Critical, + "6" => LogLevel.None, + _ => null, + }; +}