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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user