c# Nlog 非xml cs方法配置

 1         public static void InitLog(TargetWithLayout target = null, string level = "Debug", string logger = "*")
 2         {
 3 
 4             LoggingConfiguration logConfig = LogManager.Configuration ?? new LoggingConfiguration();
 5 
 6             if (target == null) target = new ConsoleTarget();
 7 
 8             if (target.Name == null) target.Name = target.GetType().Name;
 9 
10             logConfig.AddTarget(target.Name, target);
11 
12             logConfig.LoggingRules.Add(new LoggingRule(logger, LogLevel.FromString(level), target));
13 
14             LogManager.Configuration = logConfig;
15 
16         }

建议 依赖 

<package id="Anotar.NLog.Fody" version="3.3.0" targetFramework="net40" developmentDependency="true" />
<package id="Fody" version="2.1.0" targetFramework="net40" developmentDependency="true" />
<package id="NLog" version="4.4.11" targetFramework="net40" />
<package id="NLog.Windows.Forms" version="4.2.3" targetFramework="net40" />

posted @ 2017-06-29 10:54  月渊  阅读(604)  评论(0)    收藏  举报