diff --git a/Dalamud.Extensions.MicrosoftLogging/Dalamud.Extensions.MicrosoftLogging.csproj b/Dalamud.Extensions.MicrosoftLogging/Dalamud.Extensions.MicrosoftLogging.csproj index 93eea18..556c90d 100644 --- a/Dalamud.Extensions.MicrosoftLogging/Dalamud.Extensions.MicrosoftLogging.csproj +++ b/Dalamud.Extensions.MicrosoftLogging/Dalamud.Extensions.MicrosoftLogging.csproj @@ -1,18 +1,18 @@ - net7.0 + net7.0-windows enable enable Dalamud.Extensions.MicrosoftLogging - 1.0.0 + 2.0.0 Liza Carvelli MIT - https://github.com/carvelli/Dalamud.Extensions.MicrosoftLogging - https://github.com/carvelli/Dalamud.Extensions.MicrosoftLogging.git + https://git.carvel.li/liza/Dalamud.Extensions.MicrosoftLogging + https://git.carvel.li/liza/Dalamud.Extensions.MicrosoftLogging.git git true portable diff --git a/Dalamud.Extensions.MicrosoftLogging/DalamudLogger.cs b/Dalamud.Extensions.MicrosoftLogging/DalamudLogger.cs index 4fbfef2..0d491fb 100644 --- a/Dalamud.Extensions.MicrosoftLogging/DalamudLogger.cs +++ b/Dalamud.Extensions.MicrosoftLogging/DalamudLogger.cs @@ -1,6 +1,7 @@ using System.Reflection; using Microsoft.Extensions.Logging; using System.Text; +using Dalamud.Plugin.Services; using Serilog.Events; namespace Dalamud.Extensions.MicrosoftLogging @@ -8,19 +9,14 @@ namespace Dalamud.Extensions.MicrosoftLogging public sealed class DalamudLogger : ILogger { private readonly string _name; - private readonly string _assemblyName; private readonly IExternalScopeProvider? _scopeProvider; - private readonly Serilog.ILogger _pluginLogDelegate; + private readonly IPluginLog _pluginLogDelegate; - public DalamudLogger(string name, Assembly assembly, IExternalScopeProvider? scopeProvider) + public DalamudLogger(string name, IExternalScopeProvider? scopeProvider, IPluginLog pluginLogDelegate) { _name = name; - _assemblyName = assembly.GetName().Name ?? - typeof(DalamudLogger).Assembly.GetName().Name ?? - "{unknown DalamudLogger}"; _scopeProvider = scopeProvider; - _pluginLogDelegate = - Serilog.Log.ForContext("SourceContext", _assemblyName); + _pluginLogDelegate = pluginLogDelegate; } public IDisposable BeginScope(TState state) @@ -29,7 +25,7 @@ namespace Dalamud.Extensions.MicrosoftLogging public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None && IsEnabled(ToSerilogLevel(logLevel)); - private bool IsEnabled(LogEventLevel logEventLevel) => _pluginLogDelegate.IsEnabled(logEventLevel); + private bool IsEnabled(LogEventLevel logEventLevel) => logEventLevel >= _pluginLogDelegate.MinimumLogLevel; public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) @@ -45,7 +41,6 @@ namespace Dalamud.Extensions.MicrosoftLogging throw new ArgumentNullException(nameof(formatter)); StringBuilder sb = new StringBuilder(); - sb.Append('[').Append(_assemblyName).Append("] "); _scopeProvider?.ForEachScope((scope, builder) => { if (scope is IEnumerable> properties) diff --git a/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerExtensions.cs b/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerExtensions.cs index b27ba39..ed623e9 100644 --- a/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerExtensions.cs +++ b/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerExtensions.cs @@ -1,4 +1,4 @@ -using Dalamud.Plugin; +using Dalamud.Plugin.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; @@ -8,11 +8,11 @@ namespace Dalamud.Extensions.MicrosoftLogging public static class DalamudLoggerExtensions { public static ILoggingBuilder AddDalamudLogger( - this ILoggingBuilder builder, IDalamudPlugin dalamudPlugin) + this ILoggingBuilder builder, IPluginLog pluginLog) { builder.Services.TryAddEnumerable( ServiceDescriptor.Singleton( - new DalamudLoggerProvider(dalamudPlugin.GetType().Assembly))); + new DalamudLoggerProvider(pluginLog))); return builder; } } diff --git a/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerProvider.cs b/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerProvider.cs index 2e89ab8..36c89c8 100644 --- a/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerProvider.cs +++ b/Dalamud.Extensions.MicrosoftLogging/DalamudLoggerProvider.cs @@ -1,16 +1,16 @@ -using System.Reflection; +using Dalamud.Plugin.Services; using Microsoft.Extensions.Logging; namespace Dalamud.Extensions.MicrosoftLogging { public sealed class DalamudLoggerProvider : ILoggerProvider, ISupportExternalScope { - private readonly Assembly _assembly; + private readonly IPluginLog _pluginLog; private IExternalScopeProvider? _scopeProvider; - public DalamudLoggerProvider(Assembly assembly) + public DalamudLoggerProvider(IPluginLog pluginLog) { - _assembly = assembly; + _pluginLog = pluginLog; } ILogger ILoggerProvider.CreateLogger(string categoryName) @@ -29,7 +29,7 @@ namespace Dalamud.Extensions.MicrosoftLogging => CreateLoggerImpl(typeof(T).FullName ?? typeof(T).ToString()); private ILogger CreateLoggerImpl(string categoryName) - => new DalamudLogger(categoryName, _assembly, _scopeProvider); + => new DalamudLogger(categoryName, _scopeProvider, _pluginLog); public void SetScopeProvider(IExternalScopeProvider scopeProvider) {