private static void Output(EventLogEntry entry, EvTailConfigurationModel configuration, StreamWriter outputFile) { var msg = string.Format("{0} {1} {2}", entry.TimeGenerated, entry.Source, entry.Message); if (configuration.outputToConsole) { Console.Write(msg); } outputFile?.Write(msg); outputFile?.Flush(); if (!entry.Message.EndsWith(Environment.NewLine)) { Console.Write(Environment.NewLine); outputFile?.Write(Environment.NewLine); } }
private static void TailEventLog(EvTailConfigurationModel configuration) { if (!string.IsNullOrEmpty(configuration.outputFile)) { _outputFile = new StreamWriter(configuration.outputFile, true); } var el = new EventLog(configuration.logName, Environment.MachineName); el.EntryWritten += (sender, eargs) => { var entry = eargs.Entry; SetConsoleColors(entry.Source, entry.Message, configuration.errorStrings); Output(entry, configuration, _outputFile); ReSetConsoleColors(); }; el.EnableRaisingEvents = true; }