diff --git a/Pal.Client/DependencyInjection/Logging/DalamudLogger.cs b/Pal.Client/DependencyInjection/Logging/DalamudLogger.cs index 1d65fc6..692c311 100644 --- a/Pal.Client/DependencyInjection/Logging/DalamudLogger.cs +++ b/Pal.Client/DependencyInjection/Logging/DalamudLogger.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Text; using Serilog.Events; @@ -24,12 +23,18 @@ namespace Pal.Client.DependencyInjection.Logging where TState : notnull => _scopeProvider?.Push(state) ?? NullScope.Instance; - public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None && PluginLogDelegate.IsEnabled(ToSerilogLevel(logLevel)); + public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None && IsEnabled(ToSerilogLevel(logLevel)); + + private bool IsEnabled(LogEventLevel logEventLevel) => PluginLogDelegate.IsEnabled(logEventLevel); public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { - if (!IsEnabled(logLevel)) + if (logLevel == LogLevel.None) + return; + + LogEventLevel logEventLevel = ToSerilogLevel(logLevel); + if (!IsEnabled(logEventLevel)) return; if (formatter == null) @@ -52,7 +57,7 @@ namespace Pal.Client.DependencyInjection.Logging }, sb); sb.Append(_name).Append(": ").Append(formatter(state, null)); - PluginLogDelegate.Write(ToSerilogLevel(logLevel), exception, sb.ToString()); + PluginLogDelegate.Write(logEventLevel, exception, sb.ToString()); } private LogEventLevel ToSerilogLevel(LogLevel logLevel) diff --git a/Pal.Client/DependencyInjectionContext.cs b/Pal.Client/DependencyInjectionContext.cs index eec832d..feaf1a8 100644 --- a/Pal.Client/DependencyInjectionContext.cs +++ b/Pal.Client/DependencyInjectionContext.cs @@ -206,6 +206,11 @@ namespace Pal.Client catch (ObjectDisposedException) { } + catch (TaskCanceledException e) + { + _logger.LogError(e, "Task cancelled"); + chat?.Error("Plugin was unloaded before it finished loading."); + } catch (Exception e) { _logger.LogError(e, "Async load failed");