From a799505c782c94930d545efc2cf144664f7d6cc6 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 26 Mar 2022 17:27:43 -0400 Subject: [PATCH] Fix actual log function not handling exceptions Closes #252 --- ProjectLighthouse/Helpers/InfluxHelper.cs | 37 ++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/ProjectLighthouse/Helpers/InfluxHelper.cs b/ProjectLighthouse/Helpers/InfluxHelper.cs index 5fc66bfc..98aa74b5 100644 --- a/ProjectLighthouse/Helpers/InfluxHelper.cs +++ b/ProjectLighthouse/Helpers/InfluxHelper.cs @@ -26,23 +26,32 @@ public static class InfluxHelper public static async void Log() { - using WriteApi writeApi = Client.GetWriteApi(); - PointData point = PointData.Measurement("lighthouse") - .Field("playerCount", await StatisticsHelper.RecentMatches()) - .Field("slotCount", await StatisticsHelper.SlotCount()); - - foreach (GameVersion gameVersion in gameVersions) + try { - PointData gamePoint = PointData.Measurement("lighthouse") - .Tag("game", gameVersion.ToString()) - .Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(gameVersion)); + using WriteApi writeApi = Client.GetWriteApi(); + PointData point = PointData.Measurement("lighthouse") + .Field("playerCount", await StatisticsHelper.RecentMatches()) + .Field("slotCount", await StatisticsHelper.SlotCount()); - writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, gamePoint); + foreach (GameVersion gameVersion in gameVersions) + { + PointData gamePoint = PointData.Measurement("lighthouse") + .Tag("game", gameVersion.ToString()) + .Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(gameVersion)); + + writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, gamePoint); + } + + writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point); + + writeApi.Flush(); } + catch(Exception e) + { + Logger.Log("Exception while logging: ", LoggerLevelInflux.Instance); - writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point); - - writeApi.Flush(); + foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance); + } } public static async Task StartLogging() @@ -61,7 +70,7 @@ public static class InfluxHelper } catch(Exception e) { - Logger.Log("Exception while logging: ", LoggerLevelInflux.Instance); + Logger.Log("Exception while running log thread: ", LoggerLevelInflux.Instance); foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance); }