public static void ConfigureForConsoleLogging(LogLevel minLevel) { ConsoleTarget consoleTarget = new ConsoleTarget(); LoggingConfiguration config = new LoggingConfiguration(); LoggingRule rule = new LoggingRule("*", minLevel, consoleTarget); config.LoggingRules.Add(rule); LogManager.Configuration = config; }
/// <summary> /// Configures NLog for to log to the specified target so that all messages /// above and including the specified level are output. /// </summary> /// <param name="target">The target to log all messages to.</param> /// <param name="minLevel">The minimal logging level.</param> public static void ConfigureForTargetLogging(Target target, LogLevel minLevel) { LoggingConfiguration config = new LoggingConfiguration(); LoggingRule rule = new LoggingRule("*", minLevel, target); config.LoggingRules.Add(rule); LogManager.Configuration = config; }
private void InitializeNLog() { var sdCard = Environment.ExternalStorageDirectory; var logDirectory = new File(sdCard.AbsolutePath + "/log"); logDirectory.Mkdirs(); var config = new LoggingConfiguration(); var csvFileTarget = new FileTarget { FileName = logDirectory.AbsolutePath + "/${shortdate}.csv" , Layout = new CsvLayout { Columns = { new CsvColumn("Time", "${longdate}"), new CsvColumn("Level", "${level}"), new CsvColumn("Lessage", "${message}"), new CsvColumn("Logger", "${logger}") }, } }; var lumberMillTarget = new LumberMillTarget(_androidId); config.AddTarget("CSV Logfile", csvFileTarget); config.AddTarget("Lumbermill Log", lumberMillTarget); var rule1 = new LoggingRule("*", LogLevel.Trace, csvFileTarget); config.LoggingRules.Add(rule1); var rule2 = new LoggingRule("*", LogLevel.Trace, lumberMillTarget); config.LoggingRules.Add(rule2); LogManager.Configuration = config; _logger = LogManager.GetCurrentClassLogger(); _logger.Info("NLog successfully initialized."); _logger.Debug("Application starting up..."); }