Skip to content

Commit e06373e

Browse files
committed
Added the ability to set the user identity on every event.
This is useful on desktop applications
1 parent c0d7f2c commit e06373e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Source/Shared/Extensions/ExceptionlessConfigurationExtensions.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,41 @@ public static void SetVersion(this ExceptionlessConfiguration config, Version ve
3333

3434
config.DefaultData[Event.KnownDataKeys.Version] = version.ToString();
3535
}
36-
36+
37+
/// <summary>
38+
/// Automatically set the user identity (ie. email address, username, user id) on events.
39+
/// </summary>
40+
/// <param name="config">The configuration object</param>
41+
/// <param name="identity">The user's identity that the event happened to.</param>
42+
public static void SetUserIdentity(this ExceptionlessConfiguration config, string identity) {
43+
config.SetUserIdentity(identity, null);
44+
}
45+
46+
/// <summary>
47+
/// Automatically set the user identity (ie. email address, username, user id) on events.
48+
/// </summary>
49+
/// <param name="config">The configuration object</param>
50+
/// <param name="identity">The user's identity that the event happened to.</param>
51+
/// <param name="name">The user's friendly name that the event happened to.</param>
52+
public static void SetUserIdentity(this ExceptionlessConfiguration config, string identity, string name) {
53+
if (String.IsNullOrWhiteSpace(identity) && String.IsNullOrWhiteSpace(name))
54+
return;
55+
56+
config.DefaultData[Event.KnownDataKeys.UserInfo] = new UserInfo(identity, name);
57+
}
58+
59+
/// <summary>
60+
/// Automatically set the user identity (ie. email address, username, user id) on events.
61+
/// </summary>
62+
/// <param name="config">The configuration object</param>
63+
/// <param name="userInfo">The user's identity that the event happened to.</param>
64+
public static void SetUserIdentity(this ExceptionlessConfiguration config, UserInfo userInfo) {
65+
if (userInfo == null)
66+
return;
67+
68+
config.DefaultData[Event.KnownDataKeys.UserInfo] = userInfo;
69+
}
70+
3771
public static string GetQueueName(this ExceptionlessConfiguration config) {
3872
return !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey.Substring(0, 8) : null;
3973
}

0 commit comments

Comments
 (0)