Skip to content

Commit 62db9ab

Browse files
committed
Parser 在源生成器中不应出现
1 parent 3b71aa6 commit 62db9ab

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

src/dotnetCampus.Logger/LogLevel.g.cs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,53 +42,3 @@ public enum LogLevel
4242
/// </summary>
4343
None = 6,
4444
}
45-
46-
/// <summary>
47-
/// 辅助将字符串解析为日志级别。
48-
/// </summary>
49-
public static class LogLevelParser
50-
{
51-
/// <summary>
52-
/// 尝试解析字符串为日志级别,支持常用的日志级别别名,大小写不敏感。
53-
/// </summary>
54-
/// <param name="text">要解析的字符串。</param>
55-
/// <returns>日志级别。</returns>
56-
/// <remarks>
57-
/// 目前已支持的别名有:
58-
/// <list type="bullet">
59-
/// <item><description>追踪级:0, trace, tracing</description></item>
60-
/// <item><description>调试级:1, debug, debugging</description></item>
61-
/// <item><description>一般级:2, info, information</description></item>
62-
/// <item><description>警告级:3, warn, warning</description></item>
63-
/// <item><description>错误级:4, err, error</description></item>
64-
/// <item><description>崩溃级:5, critical, fatal</description></item>
65-
/// <item><description>无日志:6, no, none</description></item>
66-
/// </list>
67-
/// 其他所有字符串均返回 <see langword="null"/>。
68-
/// </remarks>
69-
public static LogLevel? Parse(string text) => text.ToLowerInvariant() switch
70-
{
71-
"trace" => LogLevel.Trace,
72-
"tracing" => LogLevel.Trace,
73-
"debug" => LogLevel.Debug,
74-
"debugging" => LogLevel.Debug,
75-
"info" => LogLevel.Information,
76-
"information" => LogLevel.Information,
77-
"warn" => LogLevel.Warning,
78-
"warning" => LogLevel.Warning,
79-
"err" => LogLevel.Error,
80-
"error" => LogLevel.Error,
81-
"critical" => LogLevel.Critical,
82-
"fatal" => LogLevel.Critical,
83-
"no" => LogLevel.None,
84-
"none" => LogLevel.None,
85-
"0" => LogLevel.Trace,
86-
"1" => LogLevel.Debug,
87-
"2" => LogLevel.Information,
88-
"3" => LogLevel.Warning,
89-
"4" => LogLevel.Error,
90-
"5" => LogLevel.Critical,
91-
"6" => LogLevel.None,
92-
_ => null,
93-
};
94-
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace dotnetCampus.Logging;
2+
3+
/// <summary>
4+
/// 辅助将字符串解析为日志级别。
5+
/// </summary>
6+
public static class LogLevelParser
7+
{
8+
/// <summary>
9+
/// 尝试解析字符串为日志级别,支持常用的日志级别别名,大小写不敏感。
10+
/// </summary>
11+
/// <param name="text">要解析的字符串。</param>
12+
/// <returns>日志级别。</returns>
13+
/// <remarks>
14+
/// 目前已支持的别名有:
15+
/// <list type="bullet">
16+
/// <item><description>追踪级:0, trace, tracing</description></item>
17+
/// <item><description>调试级:1, debug, debugging</description></item>
18+
/// <item><description>一般级:2, info, information</description></item>
19+
/// <item><description>警告级:3, warn, warning</description></item>
20+
/// <item><description>错误级:4, err, error</description></item>
21+
/// <item><description>崩溃级:5, critical, fatal</description></item>
22+
/// <item><description>无日志:6, no, none</description></item>
23+
/// </list>
24+
/// 其他所有字符串均返回 <see langword="null"/>。
25+
/// </remarks>
26+
public static LogLevel? Parse(string text) => text.ToLowerInvariant() switch
27+
{
28+
"trace" => LogLevel.Trace,
29+
"tracing" => LogLevel.Trace,
30+
"debug" => LogLevel.Debug,
31+
"debugging" => LogLevel.Debug,
32+
"info" => LogLevel.Information,
33+
"information" => LogLevel.Information,
34+
"warn" => LogLevel.Warning,
35+
"warning" => LogLevel.Warning,
36+
"err" => LogLevel.Error,
37+
"error" => LogLevel.Error,
38+
"critical" => LogLevel.Critical,
39+
"fatal" => LogLevel.Critical,
40+
"no" => LogLevel.None,
41+
"none" => LogLevel.None,
42+
"0" => LogLevel.Trace,
43+
"1" => LogLevel.Debug,
44+
"2" => LogLevel.Information,
45+
"3" => LogLevel.Warning,
46+
"4" => LogLevel.Error,
47+
"5" => LogLevel.Critical,
48+
"6" => LogLevel.None,
49+
_ => null,
50+
};
51+
}

0 commit comments

Comments
 (0)