Skip to content

Commit 26c0d7f

Browse files
committed
#158 .NET: Created a SingleSessionPlugin that only runs on the Winforms and Wpf clients
By default a wpf app and winforms client is only going to have a single user, but a user would want to track multiple sessions. This ensures that happens.
1 parent 90da26f commit 26c0d7f

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

Source/Extras/Exceptionless.Extras.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="Plugins\ErrorPlugin.cs" />
5555
<Compile Include="Plugins\PrivateInformationPlugin.cs" />
5656
<Compile Include="Plugins\TraceLogPlugin.cs" />
57+
<Compile Include="Plugins\SingleSessionPlugin.cs" />
5758
<Compile Include="Plugins\VersionPlugin.cs" />
5859
<Compile Include="ExceptionlessSection.cs" />
5960
<Compile Include="Extensions\EventBuilderExtensions.cs" />

Source/Extras/Extensions/ExceptionlessExtraConfigurationExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Exceptionless.Extras.Storage;
1414
using Exceptionless.Extras.Utility;
1515
using Exceptionless.Logging;
16+
using Exceptionless.Plugins;
1617
using Exceptionless.Storage;
1718

1819
namespace Exceptionless {
@@ -28,6 +29,14 @@ public static void UseErrorPlugin(this ExceptionlessConfiguration config) {
2829
config.AddPlugin<Plugins.ErrorPlugin>();
2930
}
3031

32+
/// <summary>
33+
/// Ensures only a single user session will be created unless you specify a session id via the event builder.
34+
/// NOTE: This should only be used on deskop applications. Using this in web farm scenarios is not advisable.
35+
/// </summary>
36+
public static void UseSingleSessionPlugin(this ExceptionlessConfiguration config) {
37+
config.AddPlugin<SingleSessionPlugin>();
38+
}
39+
3140
public static void UseIsolatedStorage(this ExceptionlessConfiguration config) {
3241
config.Resolver.Register<IObjectStorage>(new IsolatedStorageObjectStorage(config.Resolver));
3342
}

Source/Extras/Plugins/PrivateInformationPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public void Run(EventPluginContext context) {
88
return;
99

1010
var user = context.Event.GetUserIdentity();
11-
if (user == null || String.IsNullOrEmpty(user.Identity))
11+
if (String.IsNullOrEmpty(user?.Identity))
1212
context.Event.SetUserIdentity(Environment.UserName);
1313
}
1414
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Exceptionless.Plugins {
4+
[Priority(90)]
5+
public class SingleSessionPlugin : IEventPlugin {
6+
private readonly string _sessionId = Guid.NewGuid().ToString("N").Substring(0, 16);
7+
8+
public void Run(EventPluginContext context) {
9+
if (String.IsNullOrEmpty(context.Event.SessionId))
10+
context.Event.SessionId = _sessionId;
11+
}
12+
}
13+
}

Source/Platforms/Windows/ExceptionlessWindowsExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ public static class ExceptionlessWindowsExtensions {
1515
/// <param name="client">The ExceptionlessClient.</param>
1616
/// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
1717
public static void Register(this ExceptionlessClient client, bool showDialog = true) {
18+
client.Configuration.UseSingleSessionPlugin();
1819
client.Startup();
1920
client.RegisterApplicationThreadExceptionHandler();
2021

2122
// make sure that queued events are sent when the app exits
2223
client.RegisterOnProcessExitHandler();
23-
24+
2425
if (!showDialog)
2526
return;
2627

Source/Platforms/Wpf/ExceptionlessWpfExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class ExceptionlessWpfExtensions {
1616
/// <param name="client">The ExceptionlessClient.</param>
1717
/// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
1818
public static void Register(this ExceptionlessClient client, bool showDialog = true) {
19+
client.Configuration.UseSingleSessionPlugin();
1920
client.Startup();
2021
client.RegisterApplicationThreadExceptionHandler();
2122
client.RegisterApplicationDispatcherUnhandledExceptionHandler();

0 commit comments

Comments
 (0)