-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathEventBuilder.cs
More file actions
163 lines (143 loc) · 6.48 KB
/
Copy pathEventBuilder.cs
File metadata and controls
163 lines (143 loc) · 6.48 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using Exceptionless.Plugins;
using Exceptionless.Models;
namespace Exceptionless {
public class EventBuilder {
public EventBuilder(Event ev, ExceptionlessClient client = null, ContextData pluginContextData = null) {
Client = client ?? ExceptionlessClient.Default;
Target = ev;
PluginContextData = pluginContextData ?? new ContextData();
}
/// <summary>
/// Any contextual data objects to be used by Exceptionless plugins to gather additional
/// information for inclusion in the event.
/// </summary>
public ContextData PluginContextData { get; private set; }
public ExceptionlessClient Client { get; set; }
public Event Target { get; private set; }
/// <summary>
/// Sets the event type.
/// </summary>
/// <param name="type">The event type.</param>
public EventBuilder SetType(string type) {
Target.Type = type;
return this;
}
/// <summary>
/// Sets the event source.
/// </summary>
/// <param name="source">The event source.</param>
public EventBuilder SetSource(string source) {
Target.Source = source;
return this;
}
/// <summary>
/// Sets the event reference id.
/// </summary>
/// <param name="referenceId">The event reference id.</param>
public EventBuilder SetReferenceId(string referenceId) {
Target.SetReferenceId(referenceId);
return this;
}
/// <summary>
/// Allows you to reference a parent event by its <seealso cref="Event.ReferenceId" /> property. This allows you to have parent and child relationships.
/// </summary>
/// <param name="name">Reference name</param>
/// <param name="id">The reference id that points to a specific event</param>
public EventBuilder SetEventReference(string name, string id) {
Target.SetEventReference(name, id);
return this;
}
/// <summary>
/// Sets the event message.
/// </summary>
/// <param name="message">The event message.</param>
public EventBuilder SetMessage(string message) {
Target.Message = message;
return this;
}
/// <summary>
/// Sets the event exception object.
/// </summary>
/// <param name="ex">The exception</param>
public EventBuilder SetException(Exception ex) {
PluginContextData.SetException(ex);
return this;
}
/// <summary>
/// Sets the event geo coordinates. Can be either "lat,lon" or an IP address that will be used to auto detect the geo coordinates.
/// </summary>
/// <param name="coordinates">The event coordinates.</param>
public EventBuilder SetGeo(string coordinates) {
Target.SetGeo(coordinates);
return this;
}
/// <summary>
/// Sets the event geo coordinates.
/// </summary>
/// <param name="latitude">The event latitude.</param>
/// <param name="longitude">The event longitude.</param>
public EventBuilder SetGeo(double latitude, double longitude) {
Target.SetGeo(latitude, longitude);
return this;
}
/// <summary>
/// Sets the event value.
/// </summary>
/// <param name="value">The value of the event.</param>
public EventBuilder SetValue(decimal value) {
Target.Value = value;
return this;
}
/// <summary>
/// Adds one or more tags to the event.
/// </summary>
/// <param name="tags">The tags to be added to the event.</param>
public EventBuilder AddTags(params string[] tags) {
Target.AddTags(tags);
return this;
}
/// <summary>
/// Sets an extended property value to include with the event. Use either <paramref name="excludedPropertyNames" /> or
/// <see cref="System.Text.Json.Serialization.JsonIgnoreAttribute" /> to exclude data from being included in the event report.
/// </summary>
/// <param name="name">The name of the object to add.</param>
/// <param name="value">The data object to add.</param>
/// <param name="maxDepth">The max depth of the object to include.</param>
/// <param name="excludedPropertyNames">Any property names that should be excluded.</param>
/// <param name="ignoreSerializationErrors">Specifies if properties that throw serialization errors should be ignored.</param>
public EventBuilder SetProperty(string name, object value, int? maxDepth = null, ICollection<string> excludedPropertyNames = null, bool ignoreSerializationErrors = false) {
if (value != null)
Target.AddObject(value, name, maxDepth, excludedPropertyNames, ignoreSerializationErrors);
return this;
}
/// <summary>
/// Adds the object to extended data. Use either <paramref name="excludedPropertyNames" /> or
/// <see cref="System.Text.Json.Serialization.JsonIgnoreAttribute" /> to exclude data from being included in the event.
/// </summary>
/// <param name="data">The data object to add.</param>
/// <param name="name">The name of the object to add.</param>
/// <param name="maxDepth">The max depth of the object to include.</param>
/// <param name="excludedPropertyNames">Any property names that should be excluded.</param>
/// <param name="ignoreSerializationErrors">Specifies if properties that throw serialization errors should be ignored.</param>
public EventBuilder AddObject(object data, string name = null, int? maxDepth = null, ICollection<string> excludedPropertyNames = null, bool ignoreSerializationErrors = false) {
if (data != null)
Target.AddObject(data, name, maxDepth, excludedPropertyNames, ignoreSerializationErrors);
return this;
}
/// <summary>
/// Marks the event as being a critical occurrence.
/// </summary>
public EventBuilder MarkAsCritical() {
Target.MarkAsCritical();
return this;
}
/// <summary>
/// Submits the event report.
/// </summary>
public void Submit() {
Client.SubmitEvent(Target, PluginContextData);
}
}
}