1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||
using NLog; |
|||
using System.Collections.Concurrent; |
|||
|
|||
namespace SBF.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; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue