Skip to content

Commit c4644af

Browse files
committed
Made the UpdateSettingsWhenIdleInterval nullable so we know if you changed the value.
1 parent daf5080 commit c4644af

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

Source/Extras/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static void Startup(this ExceptionlessClient client, AppDomain appDomain
2727
client.Configuration.UseTraceLogEntriesPlugin();
2828
client.Configuration.AddPlugin<VersionPlugin>();
2929

30+
if (client.Configuration.UpdateSettingsWhenIdleInterval == null)
31+
client.Configuration.UpdateSettingsWhenIdleInterval = TimeSpan.FromMinutes(2);
32+
3033
client.RegisterAppDomainUnhandledExceptionHandler(appDomain);
3134
client.RegisterTaskSchedulerUnobservedTaskExceptionHandler();
3235
}

Source/Shared/Configuration/ExceptionlessConfiguration.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ExceptionlessConfiguration {
2222
private string _serverUrl;
2323
private int _submissionBatchSize;
2424
private ValidationResult _validationResult;
25-
private TimeSpan _updateSettingsWhenIdleInterval;
25+
private TimeSpan? _updateSettingsWhenIdleInterval;
2626
private readonly List<string> _exclusions = new List<string>();
2727
private readonly List<string> _userAgentBotPatterns = new List<string>();
2828
private readonly List<Func<Event, bool>> _eventExclusions = new List<Func<Event, bool>>();
@@ -42,7 +42,6 @@ public ExceptionlessConfiguration(IDependencyResolver resolver) {
4242
DefaultData = new DataDictionary();
4343
Settings = new SettingsDictionary();
4444
IncludePrivateInformation = true;
45-
_updateSettingsWhenIdleInterval = TimeSpan.FromMinutes(2);
4645

4746
_resolver = resolver;
4847

@@ -160,15 +159,15 @@ public string ApiKey {
160159
/// <summary>
161160
/// How often the client should check for updated server settings when idle. The default is every 2 minutes.
162161
/// </summary>
163-
public TimeSpan UpdateSettingsWhenIdleInterval {
162+
public TimeSpan? UpdateSettingsWhenIdleInterval {
164163
get { return _updateSettingsWhenIdleInterval; }
165164
set {
166165
if (_updateSettingsWhenIdleInterval == value)
167166
return;
168167

169-
if (value > TimeSpan.Zero && value < TimeSpan.FromSeconds(15))
168+
if (value.HasValue && value > TimeSpan.Zero && value < TimeSpan.FromSeconds(15))
170169
_updateSettingsWhenIdleInterval = TimeSpan.FromSeconds(15);
171-
else if (value <= TimeSpan.Zero)
170+
else if (value.HasValue && value <= TimeSpan.Zero)
172171
_updateSettingsWhenIdleInterval = TimeSpan.FromMilliseconds(-1);
173172
else
174173
_updateSettingsWhenIdleInterval = value;
@@ -472,8 +471,12 @@ public void Dispose() {
472471
public event EventHandler Changed;
473472

474473
protected virtual void OnChanged() {
474+
try {
475475
if (Changed != null)
476476
Changed.Invoke(this, EventArgs.Empty);
477+
} catch (Exception ex) {
478+
Resolver.GetLog().Error(typeof(ExceptionlessConfiguration), ex, "Error while calling OnChanged event handlers.");
479+
}
477480
}
478481
}
479482
}

Source/Shared/ExceptionlessClient.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ public ExceptionlessClient(ExceptionlessConfiguration configuration) {
4949

5050
_submissionClient = new Lazy<ISubmissionClient>(() => Configuration.Resolver.GetSubmissionClient());
5151
_lastReferenceIdManager = new Lazy<ILastReferenceIdManager>(() => Configuration.Resolver.GetLastReferenceIdManager());
52-
_updateSettingsTimer = new Timer(state => SettingsManager.UpdateSettings(Configuration), null, GetInitialSettingsDelay(), Configuration.UpdateSettingsWhenIdleInterval);
52+
_updateSettingsTimer = new Timer(state => SettingsManager.UpdateSettings(Configuration), null, GetInitialSettingsDelay(), Configuration.UpdateSettingsWhenIdleInterval ?? TimeSpan.FromMilliseconds(-1));
5353
}
5454

5555
private TimeSpan GetInitialSettingsDelay() {
56-
return Configuration.UpdateSettingsWhenIdleInterval > TimeSpan.Zero ? TimeSpan.FromSeconds(5) : TimeSpan.FromMilliseconds(-1);
56+
return Configuration.UpdateSettingsWhenIdleInterval != null && Configuration.UpdateSettingsWhenIdleInterval > TimeSpan.Zero ? TimeSpan.FromSeconds(5) : TimeSpan.FromMilliseconds(-1);
5757
}
5858

5959
private void OnQueueEventsPosted(object sender, EventsPostedEventArgs args) {
60-
_updateSettingsTimer.Change(Configuration.UpdateSettingsWhenIdleInterval, Configuration.UpdateSettingsWhenIdleInterval);
60+
var interval = Configuration.UpdateSettingsWhenIdleInterval ?? TimeSpan.FromMilliseconds(-1);
61+
_updateSettingsTimer.Change(interval, interval);
6162
}
6263

6364
private void OnConfigurationChanged(object sender, EventArgs e) {
64-
_updateSettingsTimer.Change(!_queue.IsValueCreated ? GetInitialSettingsDelay() : Configuration.UpdateSettingsWhenIdleInterval, Configuration.UpdateSettingsWhenIdleInterval);
65+
var interval = Configuration.UpdateSettingsWhenIdleInterval ?? TimeSpan.FromMilliseconds(-1);
66+
_updateSettingsTimer.Change(!_queue.IsValueCreated ? GetInitialSettingsDelay() : interval, interval);
6567
}
6668

6769
public ExceptionlessConfiguration Configuration { get; private set; }

Source/Shared/Queue/DefaultEventQueue.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void SuspendProcessing(TimeSpan? duration = null, bool discardFutureQueue
147147
if (!duration.HasValue)
148148
duration = TimeSpan.FromMinutes(5);
149149

150-
_log.Info(typeof(ExceptionlessClient), String.Format("Suspending processing for: {0}.", duration.Value));
150+
_log.Info(typeof(DefaultEventQueue), String.Format("Suspending processing for: {0}.", duration.Value));
151151
_suspendProcessingUntil = DateTime.Now.Add(duration.Value);
152152
_queueTimer.Change(duration.Value, _processQueueInterval);
153153

@@ -168,8 +168,12 @@ public void SuspendProcessing(TimeSpan? duration = null, bool discardFutureQueue
168168
public event EventHandler<EventsPostedEventArgs> EventsPosted;
169169

170170
protected virtual void OnEventsPosted(EventsPostedEventArgs e) {
171-
if (EventsPosted != null)
172-
EventsPosted.Invoke(this, e);
171+
try {
172+
if (EventsPosted != null)
173+
EventsPosted.Invoke(this, e);
174+
} catch (Exception ex) {
175+
_log.Error(typeof(DefaultEventQueue), ex, "Error while calling OnEventsPosted event handlers.");
176+
}
173177
}
174178

175179
private bool IsQueueProcessingSuspended {

0 commit comments

Comments
 (0)