public static void ConfigureForFileLogging(string fileName, LogLevel minLevel)
 {
     FileTarget target = new FileTarget();
     target.FileName = fileName;
     ConfigureForTargetLogging(target, minLevel);
 }
Example #2
0
        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...");
        }