-
-
Notifications
You must be signed in to change notification settings - Fork 512
Expand file tree
/
Copy pathEvent.cs
More file actions
130 lines (113 loc) · 4.42 KB
/
Event.cs
File metadata and controls
130 lines (113 loc) · 4.42 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using Exceptionless.Core.Extensions;
namespace Exceptionless.Core.Models;
[DebuggerDisplay("Type: {Type}, Date: {Date}, Message: {Message}, Value: {Value}, Count: {Count}")]
public class Event : IData
{
/// <summary>
/// The event type (ie. error, log message, feature usage). Check <see cref="KnownTypes">Event.KnownTypes</see> for standard event types.
/// </summary>
[StringLength(100)]
public string? Type { get; set; }
/// <summary>
/// The event source (ie. machine name, log name, feature name).
/// </summary>
[StringLength(2000)]
public string? Source { get; set; }
/// <summary>
/// The date that the event occurred on.
/// </summary>
public DateTimeOffset Date { get; set; }
/// <summary>
/// A list of tags used to categorize this event.
/// </summary>
public TagSet? Tags { get; set; } = [];
/// <summary>
/// The event message.
/// </summary>
[StringLength(2000)]
public string? Message { get; set; }
/// <summary>
/// The geo coordinates where the event happened.
/// </summary>
public string? Geo { get; set; }
/// <summary>
/// The value of the event if any.
/// </summary>
public decimal? Value { get; set; }
/// <summary>
/// The number of duplicated events.
/// </summary>
public int? Count { get; set; }
/// <summary>
/// Optional data entries that contain additional information about this event.
/// </summary>
public DataDictionary? Data { get; set; } = new();
/// <summary>
/// An optional identifier to be used for referencing this event instance at a later time.
/// </summary>
public string? ReferenceId { get; set; }
protected bool Equals(Event other)
{
return String.Equals(Type, other.Type) && String.Equals(Source, other.Source) && Tags.CollectionEquals(other.Tags) && String.Equals(Message, other.Message) && String.Equals(Geo, other.Geo) && Value == other.Value && Equals(Data, other.Data);
}
public override bool Equals(object? obj)
{
if (obj is null)
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != GetType())
return false;
return Equals((Event)obj);
}
private static readonly List<string> _exclusions = [KnownDataKeys.TraceLog];
public override int GetHashCode()
{
unchecked
{
int hashCode = Type?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (Source?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Tags?.GetCollectionHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Message?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Geo?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ Value.GetHashCode();
hashCode = (hashCode * 397) ^ (Data?.GetCollectionHashCode(_exclusions) ?? 0);
return hashCode;
}
}
public static class KnownTypes
{
public const string Error = "error";
public const string FeatureUsage = "usage";
public const string Log = "log";
public const string NotFound = "404";
public const string Session = "session";
public const string SessionEnd = "sessionend";
public const string SessionHeartbeat = "heartbeat";
}
public static class KnownTags
{
public const string Critical = "Critical";
public const string Internal = "Internal";
}
public static class KnownDataKeys
{
public const string Error = "@error";
public const string SimpleError = "@simple_error";
public const string RequestInfo = "@request";
public const string TraceLog = "@trace";
public const string EnvironmentInfo = "@environment";
public const string UserInfo = "@user";
public const string UserDescription = "@user_description";
public const string Version = "@version";
public const string Level = "@level";
public const string Location = "@location";
public const string SubmissionMethod = "@submission_method";
public const string SubmissionClient = "@submission_client";
public const string SessionEnd = "sessionend";
public const string SessionHasError = "haserror";
public const string ManualStackingInfo = "@stack";
}
}