Skip to content

Commit 2f95b14

Browse files
committed
Only call SubmitSessionEnd if Sessions are enabled.
1 parent 188bf10 commit 2f95b14

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

src/Exceptionless/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public static class ExceptionlessClientExtensions {
1616
/// <param name="client">The ExceptionlessClient.</param>
1717
/// <param name="apiKey">The API key that will be used when sending events to the server.</param>
1818
public static void Startup(this ExceptionlessClient client, string apiKey = null) {
19+
if (client == null)
20+
throw new ArgumentNullException(nameof(client));
21+
1922
if (!String.IsNullOrEmpty(apiKey))
2023
client.Configuration.ApiKey = apiKey;
2124

@@ -45,6 +48,9 @@ public static void Startup(this ExceptionlessClient client, string apiKey = null
4548
/// </summary>
4649
/// <param name="client">The ExceptionlessClient.</param>
4750
public static void Shutdown(this ExceptionlessClient client) {
51+
if (client == null)
52+
throw new ArgumentNullException(nameof(client));
53+
4854
#if !PORTABLE && !NETSTANDARD1_2
4955
client.UnregisterAppDomainUnhandledExceptionHandler();
5056
client.UnregisterOnProcessExitHandler();
@@ -64,6 +70,9 @@ public static void Shutdown(this ExceptionlessClient client) {
6470
/// <param name="client">The client instance.</param>
6571
/// <param name="exception">The unhandled exception.</param>
6672
public static void SubmitUnhandledException(this ExceptionlessClient client, Exception exception) {
73+
if (client == null)
74+
throw new ArgumentNullException(nameof(client));
75+
6776
var builder = exception.ToExceptionless(client: client);
6877
builder.PluginContextData.MarkAsUnhandledError();
6978
builder.Submit();
@@ -75,6 +84,9 @@ public static void SubmitUnhandledException(this ExceptionlessClient client, Exc
7584
/// <param name="client">The client instance.</param>
7685
/// <param name="exception">The exception.</param>
7786
public static void SubmitException(this ExceptionlessClient client, Exception exception) {
87+
if (client == null)
88+
throw new ArgumentNullException(nameof(client));
89+
7890
client.CreateException(exception).Submit();
7991
}
8092

@@ -84,6 +96,9 @@ public static void SubmitException(this ExceptionlessClient client, Exception ex
8496
/// <param name="client">The client instance.</param>
8597
/// <param name="exception">The exception.</param>
8698
public static EventBuilder CreateException(this ExceptionlessClient client, Exception exception) {
99+
if (client == null)
100+
throw new ArgumentNullException(nameof(client));
101+
87102
return exception.ToExceptionless(client: client);
88103
}
89104

@@ -93,6 +108,9 @@ public static EventBuilder CreateException(this ExceptionlessClient client, Exce
93108
/// <param name="client">The client instance.</param>
94109
/// <param name="message">The log message.</param>
95110
public static void SubmitLog(this ExceptionlessClient client, string message) {
111+
if (client == null)
112+
throw new ArgumentNullException(nameof(client));
113+
96114
client.CreateLog(message).Submit();
97115
}
98116

@@ -103,6 +121,9 @@ public static void SubmitLog(this ExceptionlessClient client, string message) {
103121
/// <param name="source">The log source.</param>
104122
/// <param name="message">The log message.</param>
105123
public static void SubmitLog(this ExceptionlessClient client, string source, string message) {
124+
if (client == null)
125+
throw new ArgumentNullException(nameof(client));
126+
106127
client.CreateLog(source, message).Submit();
107128
}
108129

@@ -114,6 +135,9 @@ public static void SubmitLog(this ExceptionlessClient client, string source, str
114135
/// <param name="message">The log message.</param>
115136
/// <param name="level">The log level.</param>
116137
public static void SubmitLog(this ExceptionlessClient client, string source, string message, string level) {
138+
if (client == null)
139+
throw new ArgumentNullException(nameof(client));
140+
117141
client.CreateLog(source, message, level).Submit();
118142
}
119143

@@ -125,6 +149,9 @@ public static void SubmitLog(this ExceptionlessClient client, string source, str
125149
/// <param name="message">The log message.</param>
126150
/// <param name="level">The log level.</param>
127151
public static void SubmitLog(this ExceptionlessClient client, string source, string message, LogLevel level) {
152+
if (client == null)
153+
throw new ArgumentNullException(nameof(client));
154+
128155
client.CreateLog(source, message, level.ToString()).Submit();
129156
}
130157

@@ -135,6 +162,9 @@ public static void SubmitLog(this ExceptionlessClient client, string source, str
135162
/// <param name="message">The log message.</param>
136163
/// <param name="level">The log level.</param>
137164
public static void SubmitLog(this ExceptionlessClient client, string message, LogLevel level) {
165+
if (client == null)
166+
throw new ArgumentNullException(nameof(client));
167+
138168
client.CreateLog(null, message, level.ToString()).Submit();
139169
}
140170

@@ -144,6 +174,9 @@ public static void SubmitLog(this ExceptionlessClient client, string message, Lo
144174
/// <param name="client">The client instance.</param>
145175
/// <param name="message">The log message.</param>
146176
public static EventBuilder CreateLog(this ExceptionlessClient client, string message) {
177+
if (client == null)
178+
throw new ArgumentNullException(nameof(client));
179+
147180
return client.CreateEvent().SetType(Event.KnownTypes.Log).SetMessage(message);
148181
}
149182

@@ -154,6 +187,9 @@ public static EventBuilder CreateLog(this ExceptionlessClient client, string mes
154187
/// <param name="source">The log source.</param>
155188
/// <param name="message">The log message.</param>
156189
public static EventBuilder CreateLog(this ExceptionlessClient client, string source, string message) {
190+
if (client == null)
191+
throw new ArgumentNullException(nameof(client));
192+
157193
return client.CreateLog(message).SetSource(source);
158194
}
159195

@@ -165,6 +201,9 @@ public static EventBuilder CreateLog(this ExceptionlessClient client, string sou
165201
/// <param name="message">The log message.</param>
166202
/// <param name="level">The log level.</param>
167203
public static EventBuilder CreateLog(this ExceptionlessClient client, string source, string message, string level) {
204+
if (client == null)
205+
throw new ArgumentNullException(nameof(client));
206+
168207
var builder = client.CreateLog(source, message);
169208

170209
if (!String.IsNullOrWhiteSpace(level))
@@ -181,6 +220,9 @@ public static EventBuilder CreateLog(this ExceptionlessClient client, string sou
181220
/// <param name="message">The log message.</param>
182221
/// <param name="level">The log level.</param>
183222
public static EventBuilder CreateLog(this ExceptionlessClient client, string source, string message, LogLevel level) {
223+
if (client == null)
224+
throw new ArgumentNullException(nameof(client));
225+
184226
return CreateLog(client, source, message, level.ToString());
185227
}
186228

@@ -191,6 +233,9 @@ public static EventBuilder CreateLog(this ExceptionlessClient client, string sou
191233
/// <param name="message">The log message.</param>
192234
/// <param name="level">The log level.</param>
193235
public static EventBuilder CreateLog(this ExceptionlessClient client, string message, LogLevel level) {
236+
if (client == null)
237+
throw new ArgumentNullException(nameof(client));
238+
194239
return CreateLog(client, null, message, level.ToString());
195240
}
196241

@@ -200,6 +245,9 @@ public static EventBuilder CreateLog(this ExceptionlessClient client, string mes
200245
/// <param name="client">The client instance.</param>
201246
/// <param name="feature">The name of the feature that was used.</param>
202247
public static EventBuilder CreateFeatureUsage(this ExceptionlessClient client, string feature) {
248+
if (client == null)
249+
throw new ArgumentNullException(nameof(client));
250+
203251
return client.CreateEvent().SetType(Event.KnownTypes.FeatureUsage).SetSource(feature);
204252
}
205253

@@ -209,6 +257,9 @@ public static EventBuilder CreateFeatureUsage(this ExceptionlessClient client, s
209257
/// <param name="client">The client instance.</param>
210258
/// <param name="feature">The name of the feature that was used.</param>
211259
public static void SubmitFeatureUsage(this ExceptionlessClient client, string feature) {
260+
if (client == null)
261+
throw new ArgumentNullException(nameof(client));
262+
212263
client.CreateFeatureUsage(feature).Submit();
213264
}
214265

@@ -218,6 +269,9 @@ public static void SubmitFeatureUsage(this ExceptionlessClient client, string fe
218269
/// <param name="client">The client instance.</param>
219270
/// <param name="resource">The name of the resource that was not found.</param>
220271
public static EventBuilder CreateNotFound(this ExceptionlessClient client, string resource) {
272+
if (client == null)
273+
throw new ArgumentNullException(nameof(client));
274+
221275
return client.CreateEvent().SetType(Event.KnownTypes.NotFound).SetSource(resource);
222276
}
223277

@@ -227,6 +281,9 @@ public static EventBuilder CreateNotFound(this ExceptionlessClient client, strin
227281
/// <param name="client">The client instance.</param>
228282
/// <param name="resource">The name of the resource that was not found.</param>
229283
public static void SubmitNotFound(this ExceptionlessClient client, string resource) {
284+
if (client == null)
285+
throw new ArgumentNullException(nameof(client));
286+
230287
client.CreateNotFound(resource).Submit();
231288
}
232289

@@ -235,6 +292,9 @@ public static void SubmitNotFound(this ExceptionlessClient client, string resour
235292
/// </summary>
236293
/// <param name="client">The client instance.</param>
237294
public static EventBuilder CreateSessionStart(this ExceptionlessClient client) {
295+
if (client == null)
296+
throw new ArgumentNullException(nameof(client));
297+
238298
return client.CreateEvent().SetType(Event.KnownTypes.Session);
239299
}
240300

@@ -243,6 +303,9 @@ public static EventBuilder CreateSessionStart(this ExceptionlessClient client) {
243303
/// </summary>
244304
/// <param name="client">The client instance.</param>
245305
public static void SubmitSessionStart(this ExceptionlessClient client) {
306+
if (client == null)
307+
throw new ArgumentNullException(nameof(client));
308+
246309
client.CreateSessionStart().Submit();
247310
}
248311

@@ -252,6 +315,9 @@ public static void SubmitSessionStart(this ExceptionlessClient client) {
252315
/// <param name="client">The client instance.</param>
253316
/// <param name="sessionIdOrUserId">The session id or user id.</param>
254317
public static void SubmitSessionEnd(this ExceptionlessClient client, string sessionIdOrUserId = null) {
318+
if (client == null)
319+
throw new ArgumentNullException(nameof(client));
320+
255321
sessionIdOrUserId = sessionIdOrUserId ?? client.Configuration.CurrentSessionIdentifier;
256322
if (String.IsNullOrWhiteSpace(sessionIdOrUserId))
257323
return;
@@ -266,6 +332,9 @@ public static void SubmitSessionEnd(this ExceptionlessClient client, string sess
266332
/// <param name="client">The client instance.</param>
267333
/// <param name="sessionIdOrUserId">The session id or user id.</param>
268334
public static void SubmitSessionHeartbeat(this ExceptionlessClient client, string sessionIdOrUserId = null) {
335+
if (client == null)
336+
throw new ArgumentNullException(nameof(client));
337+
269338
sessionIdOrUserId = sessionIdOrUserId ?? client.Configuration.CurrentSessionIdentifier;
270339
if (String.IsNullOrWhiteSpace(sessionIdOrUserId))
271340
return;
@@ -283,6 +352,9 @@ public static class ExceptionlessClientExtensions {
283352
#if !PORTABLE && !NETSTANDARD1_2
284353
private static UnhandledExceptionEventHandler _onAppDomainUnhandledException;
285354
public static void RegisterAppDomainUnhandledExceptionHandler(this ExceptionlessClient client) {
355+
if (client == null)
356+
throw new ArgumentNullException(nameof(client));
357+
286358
if (_onAppDomainUnhandledException == null) {
287359
_onAppDomainUnhandledException = (sender, args) => {
288360
var exception = args.ExceptionObject as Exception;
@@ -297,6 +369,9 @@ public static void RegisterAppDomainUnhandledExceptionHandler(this Exceptionless
297369

298370
// process queue immediately since the app is about to exit.
299371
client.ProcessQueue();
372+
373+
if (client.Configuration.SessionsEnabled)
374+
client.SubmitSessionEnd();
300375
};
301376
}
302377

@@ -309,6 +384,9 @@ public static void RegisterAppDomainUnhandledExceptionHandler(this Exceptionless
309384
}
310385

311386
public static void UnregisterAppDomainUnhandledExceptionHandler(this ExceptionlessClient client) {
387+
if (client == null)
388+
throw new ArgumentNullException(nameof(client));
389+
312390
if (_onAppDomainUnhandledException == null)
313391
return;
314392

@@ -318,10 +396,15 @@ public static void UnregisterAppDomainUnhandledExceptionHandler(this Exceptionle
318396

319397
private static EventHandler _onProcessExit;
320398
public static void RegisterOnProcessExitHandler(this ExceptionlessClient client) {
399+
if (client == null)
400+
throw new ArgumentNullException(nameof(client));
401+
321402
if (_onProcessExit == null) {
322403
_onProcessExit = (sender, args) => {
323404
client.ProcessQueue();
324-
client.SubmitSessionEnd();
405+
406+
if (client.Configuration.SessionsEnabled)
407+
client.SubmitSessionEnd();
325408
};
326409
}
327410

@@ -334,6 +417,9 @@ public static void RegisterOnProcessExitHandler(this ExceptionlessClient client)
334417
}
335418

336419
public static void UnregisterOnProcessExitHandler(this ExceptionlessClient client) {
420+
if (client == null)
421+
throw new ArgumentNullException(nameof(client));
422+
337423
if (_onProcessExit == null)
338424
return;
339425

src/Platforms/Exceptionless.Wpf/ExceptionlessWpfExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public static void Unregister(this ExceptionlessClient client) {
4949
client.SubmittingEvent -= OnSubmittingEvent;
5050

5151
client.ProcessQueue();
52-
client.SubmitSessionEnd();
52+
53+
if (client.Configuration.SessionsEnabled)
54+
client.SubmitSessionEnd();
5355
}
5456

5557
private static void OnSubmittingEvent(object sender, EventSubmittingEventArgs e) {

0 commit comments

Comments
 (0)