C # Nlog non-xml cs method configuration,
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 }
Suggested dependency
<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"/>