Loggerrework (#45)

* test some refactoring for cachedplayer

* rework logging

* fix saving of log level

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2023-02-18 15:23:38 +01:00
committed by GitHub
parent 7f36e80e2a
commit 2ae5d42e4d
49 changed files with 676 additions and 691 deletions

View File

@@ -11,9 +11,9 @@ using MareSynchronos.API.Dto.Files;
using MareSynchronos.API.Routes;
using MareSynchronos.Mediator;
using MareSynchronos.UI;
using MareSynchronos.Utils;
using MareSynchronos.WebAPI.Utils;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.WebAPI;
@@ -28,7 +28,7 @@ public partial class ApiController
{
if (CurrentUploads.Any())
{
Logger.Debug("Cancelling current upload");
_logger.LogDebug("Cancelling current upload");
_uploadCancellationTokenSource?.Cancel();
_uploadCancellationTokenSource?.Dispose();
_uploadCancellationTokenSource = null;
@@ -102,7 +102,7 @@ public partial class ApiController
localTimeoutCts.Dispose();
composite.Dispose();
Logger.Debug($"Download {requestId} ready");
_logger.LogDebug($"Download {requestId} ready");
}
catch (TaskCanceledException)
{
@@ -133,14 +133,14 @@ public partial class ApiController
{
var requestId = await GetQueueRequest(fileTransfer, ct).ConfigureAwait(false);
Logger.Debug($"GUID {requestId} for file {fileTransfer.Hash} on server {fileTransfer.DownloadUri}");
_logger.LogDebug($"GUID {requestId} for file {fileTransfer.Hash} on server {fileTransfer.DownloadUri}");
await WaitForDownloadReady(fileTransfer, requestId, ct).ConfigureAwait(false);
HttpResponseMessage response = null!;
var requestUrl = MareFiles.CacheGetFullPath(fileTransfer.DownloadUri, requestId);
Logger.Debug($"Downloading {requestUrl} for file {fileTransfer.Hash}");
_logger.LogDebug($"Downloading {requestUrl} for file {fileTransfer.Hash}");
try
{
response = await SendRequestAsync(HttpMethod.Get, requestUrl, ct).ConfigureAwait(false);
@@ -148,7 +148,7 @@ public partial class ApiController
}
catch (HttpRequestException ex)
{
Logger.Warn($"Error during download of {requestUrl}, HttpStatusCode: {ex.StatusCode}");
_logger.LogWarning($"Error during download of {requestUrl}, HttpStatusCode: {ex.StatusCode}");
if (ex.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Unauthorized)
{
throw new Exception($"Http error {ex.StatusCode} (cancelled: {ct.IsCancellationRequested}): {requestUrl}", ex);
@@ -173,12 +173,12 @@ public partial class ApiController
progress.Report(bytesRead);
}
Logger.Debug($"{requestUrl} downloaded to {tempPath}");
_logger.LogDebug($"{requestUrl} downloaded to {tempPath}");
}
}
catch (Exception ex)
{
Logger.Warn($"Error during file download of {requestUrl}", ex);
_logger.LogWarning($"Error during file download of {requestUrl}", ex);
try
{
if (!tempPath.IsNullOrEmpty())
@@ -220,11 +220,11 @@ public partial class ApiController
if (requestMessage.Content != null)
{
Logger.Debug("Sending " + requestMessage.Method + " to " + requestMessage.RequestUri + " (Content: " + await (((JsonContent)requestMessage.Content).ReadAsStringAsync()) + ")");
_logger.LogDebug("Sending " + requestMessage.Method + " to " + requestMessage.RequestUri + " (Content: " + await (((JsonContent)requestMessage.Content).ReadAsStringAsync()) + ")");
}
else
{
Logger.Debug("Sending " + requestMessage.Method + " to " + requestMessage.RequestUri);
_logger.LogDebug("Sending " + requestMessage.Method + " to " + requestMessage.RequestUri);
}
try
@@ -235,7 +235,7 @@ public partial class ApiController
}
catch (Exception ex)
{
Logger.Error("Error during SendRequestInternal for " + requestMessage.RequestUri, ex);
_logger.LogCritical("Error during SendRequestInternal for " + requestMessage.RequestUri, ex);
throw;
}
}
@@ -249,12 +249,12 @@ public partial class ApiController
private async Task DownloadFilesInternal(int currentDownloadId, List<FileReplacementData> fileReplacement, CancellationToken ct)
{
Logger.Debug("Downloading files (Download ID " + currentDownloadId + ")");
_logger.LogDebug("Downloading files (Download ID " + currentDownloadId + ")");
List<DownloadFileDto> downloadFileInfoFromService = new();
downloadFileInfoFromService.AddRange(await FilesGetSizes(fileReplacement.Select(f => f.Hash).ToList()).ConfigureAwait(false));
Logger.Debug("Files with size 0 or less: " + string.Join(", ", downloadFileInfoFromService.Where(f => f.Size <= 0).Select(f => f.Hash)));
_logger.LogDebug("Files with size 0 or less: " + string.Join(", ", downloadFileInfoFromService.Where(f => f.Size <= 0).Select(f => f.Hash)));
CurrentDownloads[currentDownloadId] = downloadFileInfoFromService.Distinct().Select(d => new DownloadFileTransfer(d))
.Where(d => d.CanBeTransferred).ToList();
@@ -296,13 +296,13 @@ public partial class ApiController
catch (OperationCanceledException)
{
File.Delete(tempPath);
Logger.Debug("Detected cancellation, removing " + currentDownloadId);
_logger.LogDebug("Detected cancellation, removing " + currentDownloadId);
CancelDownload(currentDownloadId);
return;
}
catch (Exception ex)
{
Logger.Error("Error during download of " + file.Hash, ex);
_logger.LogCritical("Error during download of " + file.Hash, ex);
return;
}
@@ -329,14 +329,14 @@ public partial class ApiController
}
catch (Exception ex)
{
Logger.Warn("Issue adding file to the DB");
Logger.Warn(ex.Message);
Logger.Warn(ex.StackTrace);
_logger.LogWarning("Issue adding file to the DB");
_logger.LogWarning(ex.Message);
_logger.LogWarning(ex.StackTrace);
}
}
}).ConfigureAwait(false);
Logger.Debug("Download complete, removing " + currentDownloadId);
_logger.LogDebug("Download complete, removing " + currentDownloadId);
CancelDownload(currentDownloadId);
}
@@ -350,23 +350,23 @@ public partial class ApiController
_uploadCancellationTokenSource = new CancellationTokenSource();
var uploadToken = _uploadCancellationTokenSource.Token;
Logger.Debug($"Sending Character data {data.DataHash.Value} to service {_serverManager.CurrentApiUrl}");
_logger.LogDebug($"Sending Character data {data.DataHash.Value} to service {_serverManager.CurrentApiUrl}");
HashSet<string> unverifiedUploads = VerifyFiles(data);
if (unverifiedUploads.Any())
{
await UploadMissingFiles(unverifiedUploads, uploadToken).ConfigureAwait(false);
Logger.Info("Upload complete for " + data.DataHash.Value);
_logger.LogInformation("Upload complete for " + data.DataHash.Value);
}
await PushCharacterDataInternal(data, visibleCharacters.ToList()).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Logger.Debug("Upload operation was cancelled");
_logger.LogDebug("Upload operation was cancelled");
}
catch (Exception ex)
{
Logger.Warn("Error during upload of files", ex);
_logger.LogWarning("Error during upload of files", ex);
}
finally
{
@@ -387,7 +387,7 @@ public partial class ApiController
if (verifiedTime < DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10)))
{
Logger.Verbose("Verifying " + item + ", last verified: " + verifiedTime);
_logger.LogTrace("Verifying " + item + ", last verified: " + verifiedTime);
unverifiedUploadHashes.Add(item);
}
}
@@ -399,7 +399,7 @@ public partial class ApiController
{
unverifiedUploadHashes = unverifiedUploadHashes.Where(h => _fileDbManager.GetFileCacheByHash(h) != null).ToHashSet(StringComparer.Ordinal);
Logger.Debug("Verifying " + unverifiedUploadHashes.Count + " files");
_logger.LogDebug("Verifying " + unverifiedUploadHashes.Count + " files");
var filesToUpload = await FilesSend(unverifiedUploadHashes.ToList()).ConfigureAwait(false);
foreach (var file in filesToUpload.Where(f => !f.IsForbidden))
@@ -413,7 +413,7 @@ public partial class ApiController
}
catch (Exception ex)
{
Logger.Warn("Tried to request file " + file.Hash + " but file was not present", ex);
_logger.LogWarning("Tried to request file " + file.Hash + " but file was not present", ex);
}
}
@@ -431,10 +431,10 @@ public partial class ApiController
}
var totalSize = CurrentUploads.Sum(c => c.Total);
Logger.Debug("Compressing and uploading files");
_logger.LogDebug("Compressing and uploading files");
foreach (var file in CurrentUploads.Where(f => f.CanBeTransferred && !f.IsTransferred).ToList())
{
Logger.Debug("Compressing and uploading " + file);
_logger.LogDebug("Compressing and uploading " + file);
var data = await GetCompressedFileData(file.Hash, uploadToken).ConfigureAwait(false);
CurrentUploads.Single(e => string.Equals(e.Hash, data.Item1, StringComparison.Ordinal)).Total = data.Item2.Length;
await UploadFile(data.Item2, file.Hash, uploadToken).ConfigureAwait(false);
@@ -445,15 +445,15 @@ public partial class ApiController
if (CurrentUploads.Any())
{
var compressedSize = CurrentUploads.Sum(c => c.Total);
Logger.Debug($"Compressed {UiShared.ByteToString(totalSize)} to {UiShared.ByteToString(compressedSize)} ({(compressedSize / (double)totalSize):P2})");
_logger.LogDebug($"Compressed {UiShared.ByteToString(totalSize)} to {UiShared.ByteToString(compressedSize)} ({(compressedSize / (double)totalSize):P2})");
Logger.Debug("Upload tasks complete, waiting for server to confirm");
Logger.Debug("Uploads open: " + CurrentUploads.Any(c => c.IsInTransfer));
_logger.LogDebug("Upload tasks complete, waiting for server to confirm");
_logger.LogDebug("Uploads open: " + CurrentUploads.Any(c => c.IsInTransfer));
const double waitStep = 1.0d;
while (CurrentUploads.Any(c => c.IsInTransfer) && !uploadToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(waitStep), uploadToken).ConfigureAwait(false);
Logger.Debug("Waiting for uploads to finish");
_logger.LogDebug("Waiting for uploads to finish");
}
}
@@ -467,7 +467,7 @@ public partial class ApiController
private async Task PushCharacterDataInternal(CharacterData character, List<UserData> visibleCharacters)
{
Logger.Info("Pushing character data for " + character.DataHash.Value + " to " + string.Join(", ", visibleCharacters.Select(c => c.AliasOrUID)));
_logger.LogInformation("Pushing character data for " + character.DataHash.Value + " to " + string.Join(", ", visibleCharacters.Select(c => c.AliasOrUID)));
StringBuilder sb = new();
foreach (var item in character.FileReplacements)
{
@@ -477,7 +477,7 @@ public partial class ApiController
{
sb.AppendLine($"GlamourerData for {item.Key}: {!string.IsNullOrEmpty(item.Value)}");
}
Logger.Debug("Chara data contained: " + Environment.NewLine + sb.ToString());
_logger.LogDebug("Chara data contained: " + Environment.NewLine + sb.ToString());
await UserPushData(new(visibleCharacters, character)).ConfigureAwait(false);
}

View File

@@ -1,6 +1,6 @@
using MareSynchronos.API.Dto.User;
using MareSynchronos.Utils;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.WebAPI;
@@ -22,7 +22,7 @@ public partial class ApiController
}
catch (Exception ex)
{
Logger.Warn("Failed to Push character data: " + ex.Message);
_logger.LogWarning("Failed to Push character data: " + ex.Message);
}
}
@@ -38,7 +38,6 @@ public partial class ApiController
public async Task UserSetPairPermissions(UserPermissionsDto dto)
{
Logger.Verbose("Sending UserSetPairPermissions: " + dto);
await _mareHub!.SendAsync(nameof(UserSetPairPermissions), dto).ConfigureAwait(false);
}

View File

@@ -4,8 +4,8 @@ using MareSynchronos.API.Dto;
using MareSynchronos.API.Dto.Group;
using MareSynchronos.API.Dto.User;
using MareSynchronos.Mediator;
using MareSynchronos.Utils;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.WebAPI;
@@ -19,7 +19,7 @@ public partial class ApiController
}
catch (Exception ex)
{
Logger.Error("Error on executing safely", ex);
_logger.LogCritical("Error on executing safely", ex);
}
}
@@ -55,7 +55,7 @@ public partial class ApiController
public Task Client_GroupSendFullInfo(GroupFullInfoDto dto)
{
Logger.Verbose("Client_GroupSendFullInfo: " + dto);
_logger.LogTrace("Client_GroupSendFullInfo: " + dto);
ExecuteSafely(() => _pairManager.AddGroup(dto));
return Task.CompletedTask;
}
@@ -68,7 +68,7 @@ public partial class ApiController
public Task Client_GroupSendInfo(GroupInfoDto dto)
{
Logger.Verbose("Client_GroupSendInfo: " + dto);
_logger.LogTrace("Client_GroupSendInfo: " + dto);
ExecuteSafely(() => _pairManager.SetGroupInfo(dto));
return Task.CompletedTask;
}
@@ -81,7 +81,7 @@ public partial class ApiController
public Task Client_GroupDelete(GroupDto dto)
{
Logger.Verbose("Client_GroupDelete: " + dto);
_logger.LogTrace("Client_GroupDelete: " + dto);
ExecuteSafely(() => _pairManager.RemoveGroup(dto.Group));
return Task.CompletedTask;
}
@@ -94,7 +94,7 @@ public partial class ApiController
public Task Client_GroupPairJoined(GroupPairFullInfoDto dto)
{
Logger.Verbose("Client_GroupPairJoined: " + dto);
_logger.LogTrace("Client_GroupPairJoined: " + dto);
ExecuteSafely(() => _pairManager.AddGroupPair(dto));
return Task.CompletedTask;
}
@@ -107,7 +107,7 @@ public partial class ApiController
public Task Client_GroupPairLeft(GroupPairDto dto)
{
Logger.Verbose("Client_GroupPairLeft: " + dto);
_logger.LogTrace("Client_GroupPairLeft: " + dto);
ExecuteSafely(() => _pairManager.RemoveGroupPair(dto));
return Task.CompletedTask;
}
@@ -120,7 +120,7 @@ public partial class ApiController
public Task Client_GroupChangePermissions(GroupPermissionDto dto)
{
Logger.Verbose("Client_GroupChangePermissions: " + dto);
_logger.LogTrace("Client_GroupChangePermissions: " + dto);
ExecuteSafely(() => _pairManager.SetGroupPermissions(dto));
return Task.CompletedTask;
}
@@ -133,7 +133,7 @@ public partial class ApiController
public Task Client_GroupPairChangePermissions(GroupPairUserPermissionDto dto)
{
Logger.Verbose("Client_GroupPairChangePermissions: " + dto);
_logger.LogTrace("Client_GroupPairChangePermissions: " + dto);
ExecuteSafely(() =>
{
if (string.Equals(dto.UID, UID, StringComparison.Ordinal)) _pairManager.SetGroupUserPermissions(dto);
@@ -150,7 +150,7 @@ public partial class ApiController
public Task Client_GroupPairChangeUserInfo(GroupPairUserInfoDto dto)
{
Logger.Verbose("Client_GroupPairChangeUserInfo: " + dto);
_logger.LogTrace("Client_GroupPairChangeUserInfo: " + dto);
ExecuteSafely(() =>
{
if (string.Equals(dto.UID, UID, StringComparison.Ordinal)) _pairManager.SetGroupStatusInfo(dto);
@@ -161,7 +161,7 @@ public partial class ApiController
public Task Client_UserReceiveCharacterData(OnlineUserCharaDataDto dto)
{
Logger.Verbose("Client_UserReceiveCharacterData: " + dto.User);
_logger.LogTrace("Client_UserReceiveCharacterData: " + dto.User);
ExecuteSafely(() => _pairManager.ReceiveCharaData(dto));
return Task.CompletedTask;
}
@@ -174,7 +174,7 @@ public partial class ApiController
public Task Client_UserAddClientPair(UserPairDto dto)
{
Logger.Debug($"Client_UserAddClientPair: " + dto);
_logger.LogDebug($"Client_UserAddClientPair: " + dto);
ExecuteSafely(() => _pairManager.AddUserPair(dto));
return Task.CompletedTask;
}
@@ -187,7 +187,7 @@ public partial class ApiController
public Task Client_UserRemoveClientPair(UserDto dto)
{
Logger.Debug($"Client_UserRemoveClientPair: " + dto);
_logger.LogDebug($"Client_UserRemoveClientPair: " + dto);
ExecuteSafely(() => _pairManager.RemoveUserPair(dto));
return Task.CompletedTask;
}
@@ -200,7 +200,7 @@ public partial class ApiController
public Task Client_UserSendOffline(UserDto dto)
{
Logger.Debug($"Client_UserSendOffline: {dto}");
_logger.LogDebug($"Client_UserSendOffline: {dto}");
ExecuteSafely(() => _pairManager.MarkPairOffline(dto.User));
return Task.CompletedTask;
}
@@ -213,7 +213,7 @@ public partial class ApiController
public Task Client_UserSendOnline(OnlineUserIdentDto dto)
{
Logger.Debug($"Client_UserSendOnline: {dto}");
_logger.LogDebug($"Client_UserSendOnline: {dto}");
ExecuteSafely(() => _pairManager.MarkPairOnline(dto, this));
return Task.CompletedTask;
}
@@ -226,7 +226,7 @@ public partial class ApiController
public Task Client_UserUpdateOtherPairPermissions(UserPermissionsDto dto)
{
Logger.Debug($"Client_UserUpdateOtherPairPermissions: {dto}");
_logger.LogDebug($"Client_UserUpdateOtherPairPermissions: {dto}");
ExecuteSafely(() => _pairManager.UpdatePairPermissions(dto));
return Task.CompletedTask;
}
@@ -239,7 +239,7 @@ public partial class ApiController
public Task Client_UserUpdateSelfPairPermissions(UserPermissionsDto dto)
{
Logger.Debug($"Client_UserUpdateSelfPairPermissions: {dto}");
_logger.LogDebug($"Client_UserUpdateSelfPairPermissions: {dto}");
ExecuteSafely(() => _pairManager.UpdateSelfPairPermissions(dto));
return Task.CompletedTask;
}
@@ -275,7 +275,7 @@ public partial class ApiController
public Task Client_DownloadReady(Guid requestId)
{
Logger.Debug($"Server sent {requestId} ready");
_logger.LogDebug($"Server sent {requestId} ready");
_downloadReady[requestId] = true;
return Task.CompletedTask;
}

View File

@@ -1,5 +1,4 @@
using MareSynchronos.API.Dto.Group;
using MareSynchronos.Utils;
using Microsoft.AspNetCore.SignalR.Client;
namespace MareSynchronos.WebAPI;
@@ -67,7 +66,6 @@ public partial class ApiController
public async Task GroupChangeIndividualPermissionState(GroupPairUserPermissionDto dto)
{
CheckConnection();
Logger.Debug("Sending " + dto);
await _mareHub!.SendAsync(nameof(GroupChangeIndividualPermissionState), dto).ConfigureAwait(false);
}

View File

@@ -48,10 +48,10 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
private HttpClient _httpClient;
public ApiController(MareConfigService configService, DalamudUtil dalamudUtil, FileCacheManager fileDbManager,
PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator) : base(mediator)
public ApiController(ILogger<ApiController> logger, MareConfigService configService, DalamudUtil dalamudUtil, FileCacheManager fileDbManager,
PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{
Logger.Verbose("Creating " + nameof(ApiController));
_logger.LogTrace("Creating " + nameof(ApiController));
_configService = configService;
_dalamudUtil = dalamudUtil;
@@ -107,21 +107,21 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
get => _serverState;
private set
{
Logger.Debug($"New ServerState: {value}, prev ServerState: {_serverState}");
_logger.LogDebug($"New ServerState: {value}, prev ServerState: {_serverState}");
_serverState = value;
}
}
public async Task CreateConnections(bool forceGetToken = false)
{
Logger.Debug("CreateConnections called");
_logger.LogDebug("CreateConnections called");
_httpClient?.Dispose();
_httpClient = new();
if (_serverManager.CurrentServer?.FullPause ?? true)
{
Logger.Info("Not recreating Connection, paused");
_logger.LogInformation("Not recreating Connection, paused");
_connectionDto = null;
await StopConnection(_connectionCancellationTokenSource.Token, ServerState.Disconnected).ConfigureAwait(false);
_connectionCancellationTokenSource.Cancel();
@@ -131,7 +131,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
var secretKey = _serverManager.GetSecretKey();
if (secretKey.IsNullOrEmpty())
{
Logger.Warn("No secret key set for current character");
_logger.LogWarning("No secret key set for current character");
_connectionDto = null;
await StopConnection(_connectionCancellationTokenSource.Token, ServerState.NoSecretKey).ConfigureAwait(false);
_connectionCancellationTokenSource.Cancel();
@@ -140,7 +140,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
await StopConnection(_connectionCancellationTokenSource.Token, ServerState.Disconnected).ConfigureAwait(false);
Logger.Info("Recreating Connection");
_logger.LogInformation("Recreating Connection");
_connectionCancellationTokenSource.Cancel();
_connectionCancellationTokenSource = new CancellationTokenSource();
@@ -155,11 +155,11 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
try
{
Logger.Debug("Building connection");
_logger.LogDebug("Building connection");
if (_serverManager.GetToken() == null || forceGetToken)
{
Logger.Debug("Requesting new JWT");
_logger.LogDebug("Requesting new JWT");
using HttpClient httpClient = new();
var postUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
@@ -173,12 +173,12 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
AuthFailureMessage = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
result.EnsureSuccessStatusCode();
_serverManager.SaveToken(await result.Content.ReadAsStringAsync().ConfigureAwait(false));
Logger.Debug("JWT Success");
_logger.LogDebug("JWT Success");
}
while (!_dalamudUtil.IsPlayerPresent && !token.IsCancellationRequested)
{
Logger.Debug("Player not loaded in yet, waiting");
_logger.LogDebug("Player not loaded in yet, waiting");
await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);
}
@@ -209,7 +209,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
}
catch (HttpRequestException ex)
{
Logger.Warn("HttpRequestException on Connection", ex);
_logger.LogWarning("HttpRequestException on Connection", ex);
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
@@ -219,15 +219,15 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
else
{
ServerState = ServerState.Reconnecting;
Logger.Info("Failed to establish connection, retrying");
_logger.LogInformation("Failed to establish connection, retrying");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
}
}
catch (Exception ex)
{
Logger.Warn("Exception on Connection", ex);
_logger.LogWarning("Exception on Connection", ex);
Logger.Info("Failed to establish connection, retrying");
_logger.LogInformation("Failed to establish connection, retrying");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
}
}
@@ -239,7 +239,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
{
await Task.Delay(TimeSpan.FromSeconds(30), ct).ConfigureAwait(false);
var needsRestart = await CheckClientHealth().ConfigureAwait(false);
Logger.Debug("Checked Client Health State");
_logger.LogDebug("Checked Client Health State");
}
}
@@ -247,7 +247,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
{
if (_mareHub == null) return;
Logger.Debug("Initializing data");
_logger.LogDebug("Initializing data");
OnDownloadReady((guid) => Client_DownloadReady(guid));
OnReceiveServerMessage((sev, msg) => Client_ReceiveServerMessage(sev, msg));
OnUpdateSystemInfo((dto) => Client_UpdateSystemInfo(dto));
@@ -271,12 +271,12 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
foreach (var userPair in await UserGetPairedClients().ConfigureAwait(false))
{
Logger.Debug($"Pair: {userPair}");
_logger.LogDebug($"Pair: {userPair}");
_pairManager.AddUserPair(userPair, addToLastAddedUser: false);
}
foreach (var entry in await GroupsGetAll().ConfigureAwait(false))
{
Logger.Debug($"Group: {entry}");
_logger.LogDebug($"Group: {entry}");
_pairManager.AddGroup(entry);
}
foreach (var group in _pairManager.GroupPairs.Keys)
@@ -284,7 +284,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
var users = await GroupsGetUsersInGroup(group).ConfigureAwait(false);
foreach (var user in users)
{
Logger.Debug($"GroupPair: {user}");
_logger.LogDebug($"GroupPair: {user}");
_pairManager.AddGroupPair(user);
}
}
@@ -342,7 +342,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
.WithAutomaticReconnect(new ForeverRetryPolicy(Mediator))
.ConfigureLogging(a =>
{
a.ClearProviders().AddProvider(new DalamudLoggingProvider());
a.ClearProviders().AddProvider(new DalamudLoggingProvider(_configService));
a.SetMinimumLevel(LogLevel.Information);
})
.Build();
@@ -357,7 +357,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
Mediator.Publish(new DisconnectedMessage());
_pairManager.ClearPairs();
ServerState = ServerState.Offline;
Logger.Info("Connection closed");
_logger.LogInformation("Connection closed");
return Task.CompletedTask;
}
@@ -367,7 +367,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
_healthCheckTokenSource?.Cancel();
ServerState = ServerState.Reconnecting;
Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Warning, 5000));
Logger.Warn("Connection closed... Reconnecting", arg);
_logger.LogWarning("Connection closed... Reconnecting", arg);
return Task.CompletedTask;
}
@@ -394,7 +394,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
_initialized = false;
_healthCheckTokenSource?.Cancel();
_uploadCancellationTokenSource?.Cancel();
Logger.Info("Stopping existing connection");
_logger.LogInformation("Stopping existing connection");
_mareHub.Closed -= MareHubOnClosed;
_mareHub.Reconnecting -= MareHubOnReconnecting;
_mareHub.Reconnected -= MareHubOnReconnected;