-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsageLog.cs
111 lines (104 loc) · 3.54 KB
/
UsageLog.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Text;
namespace Model
{
public class LogRecord
{
public DateTime Timestamp { get; set; }
public string Level { get; set; }
public string MessageTemplate { get; set; }
public object Properties { get; set; }
public object Renderings { get; set; }
public LogEntry ToLogEntry()
{
var entry = new LogEntry
{
Timestamp = Timestamp,
Level = Level,
MessageTemplate = MessageTemplate,
Properties = Properties.ToString(),
Renderings = Renderings == null ? null : Renderings.ToString()
};
entry.LiftSubProperties();
return entry;
}
}
public class LogEntry
{
public DateTime Timestamp { get; set; }
public string Level { get; set; }
public string MessageTemplate { get; set; }
public string Properties { get; set; }
public string Renderings { get; set; }
public string ActionId { get; set; }
public string ActionName { get; set; }
public string ConnectionId { get; set; }
public string RequestId { get; set; }
public string RequestPath { get; set; }
public string SessionId { get; set; }
public string SourceContext { get; set; }
public string User { get; set; }
public void LiftSubProperties()
{
var parsed = JObject.Parse(Properties);
var actionId = parsed[Props.ActionId];
var actionName = parsed[Props.ActionName];
var connId = parsed[Props.ConnectionId];
var reqId = parsed[Props.RequestId];
var reqPath = parsed[Props.RequestPath];
var sessId = parsed[Props.SessionId];
var sourceCtx = parsed[Props.SourceContext];
var user = parsed[Props.User];
if (actionId != null)
{
ActionId = actionId.ToString();
}
if (actionName != null)
{
ActionName = actionName.ToString();
}
if (connId != null)
{
ConnectionId = connId.ToString();
}
if (reqId != null)
{
RequestId = reqId.ToString();
}
if (reqPath != null)
{
RequestPath = reqPath.ToString();
}
if (sessId != null)
{
SessionId = sessId.ToString();
}
if (sourceCtx != null)
{
SourceContext = sourceCtx.ToString();
}
if (user != null)
{
User = user.ToString();
}
}
}
static class Props
{
public const string Timestamp = "Timestamp";
public const string Level = "Level";
public const string MessageTemplate = "MessageTemplate";
public const string Properties = "Properties";
public const string Renderings = "Renderings";
public const string ActionId = "ActionId";
public const string ActionName = "ActionName";
public const string ConnectionId = "ConnectionId";
public const string RequestId = "RequestId";
public const string RequestPath = "RequestPath";
public const string SessionId = "SessionId";
public const string SourceContext = "SourceContext";
public const string User = "User";
}
}