 2ae5d42e4d
			
		
	
	2ae5d42e4d
	
	
	
		
			
			* test some refactoring for cachedplayer * rework logging * fix saving of log level --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Collections.Concurrent;
 | |
| using MareSynchronos.MareConfiguration;
 | |
| using Microsoft.Extensions.Logging;
 | |
| 
 | |
| namespace MareSynchronos.Utils;
 | |
| 
 | |
| [ProviderAlias("Dalamud")]
 | |
| public class DalamudLoggingProvider : ILoggerProvider
 | |
| {
 | |
|     private readonly ConcurrentDictionary<string, DalamudLogger> _loggers =
 | |
|         new(StringComparer.OrdinalIgnoreCase);
 | |
|     private readonly MareConfigService _mareConfigService;
 | |
| 
 | |
|     public DalamudLoggingProvider(MareConfigService mareConfigService)
 | |
|     {
 | |
|         _mareConfigService = mareConfigService;
 | |
|     }
 | |
| 
 | |
|     public ILogger CreateLogger(string 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()
 | |
|     {
 | |
|         _loggers.Clear();
 | |
|     }
 | |
| }
 |