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.
34 lines
997 B
34 lines
997 B
using NLog;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace SiNan.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;
|
|
}
|
|
}
|
|
}
|
|
|