-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
AuditEvent.cs
109 lines (94 loc) · 3.5 KB
/
AuditEvent.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
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Audit.Core
{
/// <summary>
/// Represents the output of the audit process
/// </summary>
public class AuditEvent : IAuditOutput
{
/// <summary>
/// Indicates the change type (i.e. CustomerOrder Update)
/// </summary>
public string EventType { get; set; }
/// <summary>
/// The environment information
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AuditEventEnvironment Environment { get; set; }
#if NET6_0_OR_GREATER
/// <summary>
/// The current distributed tracing activity information
/// </summary>
public AuditActivityTrace Activity { get; set; }
#endif
/// <summary>
/// The extension data.
/// This will be serialized as the keys being properties of the current object.
/// </summary>
[JsonExtensionData]
public Dictionary<string, object> CustomFields { get; set; }
/// <summary>
/// The tracked target.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AuditTarget Target { get; set; }
/// <summary>
/// Comments.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> Comments { get; set; }
/// <summary>
/// The date then the event started
/// </summary>
public DateTime StartDate { get; set; }
/// <summary>
/// The date then the event finished
/// </summary>
public DateTime? EndDate { get; set; }
///<summary>
/// The duration of the operation in milliseconds.
/// </summary>
public int Duration { get; set; }
/// <summary>
/// A weak reference to the audit scope associated with this event.
/// </summary>
private readonly WeakReference _auditScope = new WeakReference(null);
internal void SetScope(IAuditScope auditScope)
{
_auditScope.Target = auditScope;
}
/// <summary>
/// Gets the Audit Scope associated with this Audit Event.
/// Returns NULL if the Audit Event is not associated with an Audit Scope, or after the Audit Scope has been disposed of and garbage collected.
/// </summary>
public IAuditScope GetScope()
{
return _auditScope.Target as IAuditScope;
}
/// <summary>
/// Converts the event to its JSON representation using JSON.NET.
/// </summary>
public string ToJson()
{
return Configuration.JsonAdapter.Serialize(this);
}
/// <summary>
/// Parses an AuditEvent from its JSON string representation using JSON.NET.
/// </summary>
/// <param name="json">JSON string with the audit event representation.</param>
public static T FromJson<T>(string json) where T : AuditEvent
{
return Configuration.JsonAdapter.Deserialize<T>(json);
}
/// <summary>
/// Parses an AuditEvent from its JSON string representation using JSON.NET.
/// </summary>
/// <param name="json">JSON string with the audit event representation.</param>
public static AuditEvent FromJson(string json)
{
return Configuration.JsonAdapter.Deserialize<AuditEvent>(json);
}
}
}