Fix actual log function not handling exceptions

Closes #252
This commit is contained in:
jvyden 2022-03-26 17:27:43 -04:00
commit a799505c78
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -26,23 +26,32 @@ public static class InfluxHelper
public static async void Log() public static async void Log()
{ {
using WriteApi writeApi = Client.GetWriteApi(); try
PointData point = PointData.Measurement("lighthouse")
.Field("playerCount", await StatisticsHelper.RecentMatches())
.Field("slotCount", await StatisticsHelper.SlotCount());
foreach (GameVersion gameVersion in gameVersions)
{ {
PointData gamePoint = PointData.Measurement("lighthouse") using WriteApi writeApi = Client.GetWriteApi();
.Tag("game", gameVersion.ToString()) PointData point = PointData.Measurement("lighthouse")
.Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(gameVersion)); .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); foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance);
}
writeApi.Flush();
} }
public static async Task StartLogging() public static async Task StartLogging()
@ -61,7 +70,7 @@ public static class InfluxHelper
} }
catch(Exception e) 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); foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance);
} }