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

@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using MareSynchronos.MareConfiguration;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.Utils;
@@ -6,21 +7,32 @@ namespace MareSynchronos.Utils;
[ProviderAlias("Dalamud")]
public class DalamudLoggingProvider : ILoggerProvider
{
private readonly ConcurrentDictionary<string, Logger> _loggers =
private readonly ConcurrentDictionary<string, DalamudLogger> _loggers =
new(StringComparer.OrdinalIgnoreCase);
private readonly MareConfigService _mareConfigService;
public DalamudLoggingProvider()
public DalamudLoggingProvider(MareConfigService mareConfigService)
{
_mareConfigService = mareConfigService;
}
public ILogger CreateLogger(string categoryName)
{
return _loggers.GetOrAdd(categoryName, name => new Logger(categoryName));
string catName = categoryName.Split(".", StringSplitOptions.RemoveEmptyEntries).Last();
if (catName.Length > 15)
{
catName = string.Join("", catName.Take(6)) + "..." + string.Join("", catName.TakeLast(6));
}
else
{
catName = string.Join("", Enumerable.Range(0, 15 - catName.Length).Select(_ => " ")) + catName;
}
return _loggers.GetOrAdd(catName, name => new DalamudLogger(catName, _mareConfigService));
}
public void Dispose()
{
Logger.Verbose($"Disposing {GetType()}");
_loggers.Clear();
}
}