Fixed multiple logs being written to the same bot instance
All checks were successful
EllieBotDevs/EllieHub/pipeline/head This commit looks good

This commit is contained in:
Toastie 2025-01-07 18:29:54 +13:00
parent 7fa866369c
commit 2a8cd606c5
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
4 changed files with 10 additions and 5 deletions

View file

@ -57,7 +57,7 @@ dotnet_diagnostic.CA1832.severity = warning
dotnet_diagnostic.CA1833.severity = warning
dotnet_diagnostic.CA1842.severity = warning
dotnet_diagnostic.CA1843.severity = warning
dotnet_diagnostic.CA1836.severity = warning
dotnet_diagnostic.CA1836.severity = none
dotnet_diagnostic.CA1839.severity = warning
dotnet_diagnostic.CA1840.severity = warning
dotnet_diagnostic.CA1846.severity = warning
@ -1168,7 +1168,7 @@ resharper_arrange_default_value_when_type_evident_highlighting = suggestion
resharper_arrange_default_value_when_type_not_evident_highlighting = suggestion
resharper_arrange_local_function_body_highlighting = error
resharper_arrange_method_or_operator_body_highlighting = error
resharper_arrange_missing_parentheses_highlighting = hint
resharper_arrange_missing_parentheses_highlighting = none
resharper_arrange_namespace_body_highlighting = error
resharper_arrange_object_creation_when_type_evident_highlighting = suggestion
resharper_arrange_object_creation_when_type_not_evident_highlighting = suggestion

View file

@ -12,7 +12,6 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<BuiltInComInteropSupport>True</BuiltInComInteropSupport>
<ApplicationIcon>Assets/Light/ellieupdatericon.ico</ApplicationIcon>
<NoWarn>CA1836</NoWarn>
<!--Publishing-->
<PublishSingleFile>true</PublishSingleFile>

View file

@ -11,7 +11,7 @@ namespace EllieHub.Features.BotConfig.Services;
/// </summary>
public sealed class LogWriter : ILogWriter
{
private readonly Dictionary<Guid, StringBuilder> _botLogs = new();
private readonly Dictionary<Guid, StringBuilder> _botLogs = [];
private readonly ReadOnlyAppSettings _appConfig;
/// <inheritdoc/>
@ -48,7 +48,7 @@ public sealed class LogWriter : ILogWriter
var botEntry = _appConfig.BotEntries[botId];
var now = DateTimeOffset.Now;
var date = new DateOnly(now.Year, now.Month, now.Day).ToShortDateString().Replace('/', '-');
var fileUri = Path.Combine(_appConfig.LogsDirectoryUri, $"{botEntry.Name}_v{botEntry.Version}_{date}-{now.ToUnixTimeSeconds()}.txt");
var fileUri = Path.Join(_appConfig.LogsDirectoryUri, $"{botEntry.Name}_v{botEntry.Version}_{date}-{now.ToUnixTimeSeconds()}.txt");
await File.WriteAllTextAsync(fileUri, logStringBuilder.ToString(), cToken);

View file

@ -506,6 +506,12 @@ public class BotConfigViewModel : ViewModelBase<BotConfigView>, IDisposable
/// <inheritdoc/>
public void Dispose()
{
UpdateBar.Click -= InstallOrUpdateAsync;
_botOrchestrator.OnStdout -= WriteLog;
_botOrchestrator.OnStderr -= WriteLog;
_botOrchestrator.OnBotExit -= LogBotExit;
_botOrchestrator.OnBotExit -= ReenableButtonsOnBotExit;
BotAvatar.Dispose();
GC.SuppressFinalize(this);
}