-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogAnalysis.cs
51 lines (40 loc) · 1.42 KB
/
LogAnalysis.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Text;
public static class LogAnalysis
{
// TODO: define the 'SubstringAfter()' extension method on the `string` type
public static string SubstringAfter(this string text, string start)
=> text.Split(start)[1];
// TODO: define the 'SubstringBetween()' extension method on the `string` type
public static string SubstringBetween(this string log, string start, string end)
{
var startSkip = log.Split(start);
var result = new string[startSkip.Length - 1];
for (int i = 1; i < startSkip.Length; i++)
{
var endSkip = startSkip[i].Split(end);
if (endSkip.Length > 1)
{
result[i - 1] = endSkip[0];
break;
}
result[i - 1] = startSkip[i];
}
return string.Concat(result);
}
// TODO: define the 'Message()' extension method on the `string` type
public static string Message(this string log)
=> log.Split(':')[1].Trim();
// TODO: define the 'LogLevel()' extension method on the `string` type
public static string LogLevel(this string logLine)
{
var flag = false;
var result = "";
foreach (var item in logLine)
{
if (item is ']' && flag) break;
else if (flag) result += item;
else if (flag is false && item is '[') flag = !flag;
}
return result;
}
}