6 changed files with 79 additions and 52 deletions
@ -0,0 +1,14 @@ |
|||||
|
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||
|
<targets> |
||||
|
<target name="errorFile" xsi:type="File" fileName="${basedir}/logs/${logger}/error/${shortdate}.txt" |
||||
|
layout="${longdate} | ${level:uppercase=false} ${newline}${message} ${newline}${onexception:${exception:format=tostring} ${newline}${stacktrace} ${newline}${newline}" |
||||
|
autoFlush="true"/> |
||||
|
<target name="infoFile" xsi:type="File" fileName="${basedir}/logs/${logger}/info/${shortdate}.txt" |
||||
|
layout="${longdate} | ${level:uppercase=false} ${newline}${message} ${newline}" |
||||
|
autoFlush="true"/> |
||||
|
</targets> |
||||
|
<rules> |
||||
|
<logger name="*" level="Error" writeTo="errorFile"/> |
||||
|
<logger name="*" level="Info" writeTo="infoFile" /> |
||||
|
</rules> |
||||
|
</nlog> |
@ -0,0 +1,35 @@ |
|||||
|
using NLog; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace BBWY.Server.Business |
||||
|
{ |
||||
|
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