This repository was archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNlogDataParser.cs
81 lines (76 loc) · 2.7 KB
/
NlogDataParser.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Analogy.Interfaces;
using System;
using System.Linq;
using System.Runtime.CompilerServices;
namespace Analogy.LogViewer.KamaResearch
{
public static class NlogDataParser
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AnalogyLogMessage ParseData(string data)
{
try
{
var items = data.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length == 1)
{
AnalogyLogMessage single = new AnalogyLogMessage(items.First(), AnalogyLogLevel.Error,
AnalogyLogClass.General, "N/A");
return single;
}
AnalogyLogMessage m = new AnalogyLogMessage();
if (DateTime.TryParse(items[0], out DateTime dt))
{
m.Date = dt;
}
switch (items[1])
{
case "OFF":
m.Level = AnalogyLogLevel.None;
break;
case "TRACE":
m.Level = AnalogyLogLevel.Trace;
break;
case "DEBUG":
m.Level = AnalogyLogLevel.Debug;
break;
case "INFO":
m.Level = AnalogyLogLevel.Information;
break;
case "WARN":
m.Level = AnalogyLogLevel.Warning;
break;
case "ERROR":
m.Level = AnalogyLogLevel.Error;
break;
case "FATAL":
m.Level = AnalogyLogLevel.Critical;
break;
default:
m.Level = AnalogyLogLevel.Information;
break;
}
if (items.Length == 2)
{
m.Text = items[0];
m.ProcessId = int.Parse(items[1]);
m.Level = AnalogyLogLevel.Error;
return m;
}
m.Source = items[2];
m.Module = "N/A";//items[];
if (items.Length > 4)
{
m.ProcessId = int.Parse(items[4]);
}
m.Text = items[3];
return m;
}
catch (Exception e)
{
string msg = $"Error processing line: {e}";
return new AnalogyLogMessage(msg, AnalogyLogLevel.Error, AnalogyLogClass.General, "Analogy", "None");
}
}
}
}