Ejemplo n.º 1
0
        public static void Config(this LogBase log, object config, string configName)
        {
            var titleColor           = Color.GreenYellow;
            var configColor          = Color.LimeGreen;
            var configImportantColor = Color.DeepPink;

            void PrintInitTitle(string str)
            {
                log.InfoL(str, titleColor);
                log.InfoL(new string('▀', str.Length), titleColor);
            }

            PrintInitTitle(configName);
            var json  = JsonConvert.SerializeObject(config, Formatting.Indented);
            var lines = json.Split(new[] { '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                var c = configColor;
                if (line.ToLowerInvariant().Contains("connectionstring"))
                {
                    c = configImportantColor;
                }
                log.InfoL(line, c);
            }
            log.Newline();
        }
Ejemplo n.º 2
0
        public static bool RunAndReturnStatus(string exeName, string args, string folder, LogBase log)
        {
            log.Info("Starting: ", Color.DarkGray);
            log.Info(exeName, Color.PaleGreen);
            log.Info($" {args}", Color.GhostWhite);
            log.InfoL($" (in {folder})", Color.Gray);

            using var process = new Process
                  {
                      StartInfo = new ProcessStartInfo
                      {
                          FileName               = exeName,
                          Arguments              = args,
                          UseShellExecute        = false,
                          RedirectStandardOutput = true,
                          RedirectStandardError  = true,
                          WorkingDirectory       = folder
                      }
                  };
            var lockObj = new object();

            process.OutputDataReceived += (sender, eventArgs) =>
            {
                if (eventArgs.Data == null)
                {
                    return;
                }
                lock (lockObj)
                    log.InfoL($"[out] {eventArgs.Data}", Color.PaleGreen);
            };
            process.ErrorDataReceived += (sender, eventArgs) =>
            {
                if (eventArgs.Data == null)
                {
                    return;
                }
                lock (lockObj)
                    log.InfoL($"[err] {eventArgs.Data}", Color.OrangeRed);
            };
            log.Newline();
            log.ClearPrependers();
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.WaitForExit();
            log.RestorePrependers();
            log.Newline();

            if (process.ExitCode != 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            log = new LogConsole();
            var logFile = new LogRollingFile("logfilename", new LogRollingFileOptions
            {
                MaxSizeInKb = 1024
            });

            log.AddPipe(logFile);

            log.LogTitle("Demo");

            log.Info("Hello", Color.Orange);
            log.InfoL(" World", Color.Yellow);
            log.Newline();

            TestExceptionLogging();
        }
Ejemplo n.º 4
0
        public static void LogTitle(this LogBase log, string str)
        {
            string[] GetLinesFromFont(string text)
            {
                var linesInner = new Figlet(FigletFonts.AnsiShadow).ToAscii(text).ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                linesInner = linesInner.Where(l => !string.IsNullOrEmpty(l.Trim())).ToArray();
                return(linesInner);
            }

            log.Newline();
            var lines = GetLinesFromFont(str);

            foreach (var line in lines)
            {
                log.InfoL(line, LogColors.TitleColor);
            }
            log.Newline();
        }