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); }
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(); }
public static void EmptyFolder(LogBase log, string folder) { RetryUtils.RetryFileAction(() => { foreach (var dir in Directory.GetDirectories(folder)) { Directory.Delete(dir, true); } foreach (var file in Directory.GetFiles(folder)) { File.Delete(file); } bool IsEmpty() => Directory.GetDirectories(folder).Length == 0 && Directory.GetFiles(folder).Length == 0; var isEmpty = IsEmpty(); if (!isEmpty) { throw new ApplicationException($"Folder not empty: {folder}"); } }, (i, t) => log.Info($"({(int)t.TotalSeconds}src)", Color.OrangeRed)); }
/// <summary> /// Insert [info] in the line /// </summary> /// <param name="message"></param> public static void Info(string message) { logger = new FileLogger(); logger.Info(message); }