1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-02 10:43:31 +00:00

Core - Log exceptions in timed updates, this closes #508

This commit is contained in:
SpoinkyNL 2021-01-16 18:18:27 +01:00
parent 467473f06c
commit ea6c081f22

View File

@ -2,6 +2,9 @@
using System.Threading.Tasks;
using System.Timers;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Ninject;
using Serilog;
namespace Artemis.Core
{
@ -14,9 +17,12 @@ namespace Artemis.Core
private Timer? _timer;
private bool _disposed;
private readonly object _lock = new();
private ILogger _logger;
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action)
{
_logger = CoreService.Kernel.Get<ILogger>();
Feature = feature;
Interval = interval;
Action = action;
@ -119,6 +125,8 @@ namespace Artemis.Core
if (Feature is Module module && !module.IsUpdateAllowed)
return;
try
{
if (Action != null)
Action(interval.TotalSeconds);
else if (AsyncAction != null)
@ -127,6 +135,11 @@ namespace Artemis.Core
task.Wait();
}
}
catch (Exception exception)
{
_logger.Error(exception, "Timed update uncaught exception in plugin {plugin}", Feature.Plugin);
}
}
}
private void FeatureOnEnabled(object? sender, EventArgs e)