You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
997 B
35 lines
997 B
2 years ago
|
using NLog;
|
||
|
using System.Collections.Concurrent;
|
||
|
|
||
|
namespace BBWYB.Common.Log
|
||
|
{
|
||
|
public class NLogManager
|
||
|
{
|
||
|
private ConcurrentDictionary<string, ILogger> loggerDictionary;
|
||
|
private string defaultLoggerName = "default";
|
||
|
|
||
|
public NLogManager()
|
||
|
{
|
||
|
loggerDictionary = new ConcurrentDictionary<string, ILogger>();
|
||
|
loggerDictionary.TryAdd("default", NLog.LogManager.GetLogger(defaultLoggerName));
|
||
|
}
|
||
|
|
||
|
public ILogger Default()
|
||
|
{
|
||
|
return loggerDictionary[defaultLoggerName];
|
||
|
}
|
||
|
|
||
|
public ILogger GetLogger(string loggerName)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(loggerName))
|
||
|
return Default();
|
||
|
if (!loggerDictionary.TryGetValue(loggerName, out ILogger logger))
|
||
|
{
|
||
|
logger = NLog.LogManager.GetLogger(loggerName);
|
||
|
loggerDictionary.TryAdd(loggerName, logger);
|
||
|
}
|
||
|
return logger;
|
||
|
}
|
||
|
}
|
||
|
}
|