public void Run(string[] args) { // prime the hoststring lazy instantiator hostString(); // print the thing PrintBanner(); // set up the message queue for operation BlockingMq.MakeMq(); // get a handle to the message queue singleton Mq = BlockingMq.GetMq(); // prime the UI handler SnaffCon controller = null; try { // parse cli opts in Options = Config.Parse(args); // set up the TSV output if the flag is set if (Options.LogTSV) { // treat all as strings except LastWriteTime {6} fileResultTemplate = Options.Separator + "{0}" + Options.Separator + "{1}" + Options.Separator + "{2}" + Options.Separator + "{3}" + Options.Separator + "{4}" + Options.Separator + "{5}" + Options.Separator + "{6:u}" + Options.Separator + "{7}" + Options.Separator + "{8}"; shareResultTemplate = Options.Separator + "{0}" + Options.Separator + "{1}"; dirResultTemplate = Options.Separator + "{0}" + Options.Separator + "{1}"; } // otherwise just do the normal thing else { // treat all as strings except LastWriteTime {6} fileResultTemplate = "{{{0}}}<{1}|{2}{3}|{4}|{5}|{6:u}>({7}) {8}"; shareResultTemplate = "{{{0}}}({1})"; dirResultTemplate = "{{{0}}}({1})"; } //------------------------------------------ // set up new fangled logging //------------------------------------------ LoggingConfiguration nlogConfig = new LoggingConfiguration(); ColoredConsoleTarget logconsole = null; FileTarget logfile = null; ParseLogLevelString(Options.LogLevelString); // Targets where to log to: File and Console if (Options.LogToConsole) { logconsole = new ColoredConsoleTarget("logconsole") { DetectOutputRedirected = true, UseDefaultRowHighlightingRules = false, WordHighlightingRules = { new ConsoleWordHighlightingRule("{Green}", ConsoleOutputColor.DarkGreen, ConsoleOutputColor.White), new ConsoleWordHighlightingRule("{Yellow}", ConsoleOutputColor.DarkYellow, ConsoleOutputColor.White), new ConsoleWordHighlightingRule("{Red}", ConsoleOutputColor.DarkRed, ConsoleOutputColor.White), new ConsoleWordHighlightingRule("{Black}", ConsoleOutputColor.Black, ConsoleOutputColor.White), new ConsoleWordHighlightingRule("[Trace]", ConsoleOutputColor.DarkGray, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Degub]", ConsoleOutputColor.Gray, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Info]", ConsoleOutputColor.White, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Error]", ConsoleOutputColor.Magenta, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Fatal]", ConsoleOutputColor.Red, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[File]", ConsoleOutputColor.Green, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Share]", ConsoleOutputColor.Yellow, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"<.*\|.*\|.*\|.*?>", ForegroundColor = ConsoleOutputColor.Cyan, BackgroundColor = ConsoleOutputColor.Black }, new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"^\d\d\d\d-\d\d\-\d\d \d\d:\d\d:\d\d [\+-]\d\d:\d\d ", ForegroundColor = ConsoleOutputColor.DarkGray, BackgroundColor = ConsoleOutputColor.Black }, new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"\((?:[^\)]*\)){1}", ForegroundColor = ConsoleOutputColor.DarkMagenta, BackgroundColor = ConsoleOutputColor.Black } } }; nlogConfig.AddRule(LogLevel, LogLevel.Fatal, logconsole); logconsole.Layout = "${message}"; } if (Options.LogToFile) { logfile = new FileTarget("logfile") { FileName = Options.LogFilePath }; nlogConfig.AddRule(LogLevel, LogLevel.Fatal, logfile); logfile.Layout = "${message}"; } // Apply config LogManager.Configuration = nlogConfig; //------------------------------------------- if (Options.Snaffle && (Options.SnafflePath.Length > 4)) { Directory.CreateDirectory(Options.SnafflePath); } controller = new SnaffCon(Options); Task thing = Task.Factory.StartNew(() => { controller.Execute(); }); while (true) { HandleOutput(); } } catch (Exception e) { Console.WriteLine(e.ToString()); DumpQueue(); } }
public void Run(string[] args) { PrintBanner(); MqHandle = new BlockingMq(); SnaffCon controller = null; try { Config = new Config(args, MqHandle); controller = new SnaffCon(Config); //------------------------------------------ // set up new fangled logging //------------------------------------------ var nlogConfig = new LoggingConfiguration(); ColoredConsoleTarget logconsole = null; FileTarget logfile = null; // Targets where to log to: File and Console if (Config.LogToConsole) { logconsole = new ColoredConsoleTarget("logconsole") { DetectOutputRedirected = true, UseDefaultRowHighlightingRules = false, WordHighlightingRules = { new ConsoleWordHighlightingRule("[Trace]", ConsoleOutputColor.DarkGray, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Degub]", ConsoleOutputColor.Gray, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Info]", ConsoleOutputColor.White, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Error]", ConsoleOutputColor.Magenta, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Fatal]", ConsoleOutputColor.Red, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[File]", ConsoleOutputColor.Green, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule("[Share]", ConsoleOutputColor.Yellow, ConsoleOutputColor.Black), new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"<.*\|.*\|.*\|.*?>", ForegroundColor = ConsoleOutputColor.Cyan }, new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"^\d\d\d\d-\d\d\-\d\d \d\d:\d\d:\d\d [\+-]\d\d:\d\d ", ForegroundColor = ConsoleOutputColor.DarkGray }, new ConsoleWordHighlightingRule { CompileRegex = true, Regex = @"\((?:[^\)]*\)){1}", ForegroundColor = ConsoleOutputColor.DarkMagenta } } }; nlogConfig.AddRule(Config.LogLevel, LogLevel.Fatal, logconsole); logconsole.Layout = "${message}"; } if (Config.LogToFile) { logfile = new FileTarget("logfile") { FileName = Config.LogFilePath }; nlogConfig.AddRule(Config.LogLevel, LogLevel.Fatal, logfile); logfile.Layout = "${message}"; } // Apply config LogManager.Configuration = nlogConfig; //------------------------------------------- if (Config.EnableMirror && (Config.MirrorPath.Length > 4)) { Directory.CreateDirectory(Config.MirrorPath); } var thing = Task.Factory.StartNew(() => { controller.Execute(); }); while (true) { HandleOutput(); } } catch (Exception e) { Console.WriteLine(e.ToString()); DumpQueue(); } }