public void Send() { var configvalue = ConfigurationManager.AppSettings["PROTECTED_DailyErrorLogMail"]; if (configvalue == null) { return; } configvalue = Regex.Replace(configvalue, @"\s+", ""); var receivers = configvalue.Split(','); var webLines = _logReader.Read("C:\\logs\\os2eindberetning\\web.log"); var dmzLines = _logReader.Read("C:\\logs\\os2eindberetning\\dmz.log"); var mailLines = _logReader.Read("C:\\logs\\os2eindberetning\\mail.log"); var webMessage = String.Join(Environment.NewLine, _logParser.Messages(webLines, DateTime.Now.AddDays(-1))); var dmzMessage = String.Join(Environment.NewLine, _logParser.Messages(dmzLines, DateTime.Now.AddDays(-1))); var mailMessage = String.Join(Environment.NewLine, _logParser.Messages(mailLines, DateTime.Now.AddDays(-1))); var newLine = System.Environment.NewLine; var result = ""; // Only add each header if there are log messages in that category. if (webMessage.Any()) { result += "Web:" + newLine + newLine + webMessage + newLine + newLine; } if (dmzMessage.Any()) { result += "DMZ: " + newLine + newLine + dmzMessage + newLine + newLine; } if (mailMessage.Any()) { result += "Mail: " + newLine + newLine + mailMessage; } if (result == "") { result = "Ingen fejl registreret"; } foreach (var receiver in receivers) { _mailSender.SendMail(receiver, "Log", result); } }
public void ProcessLogs() { foreach (LogEntry logEntry in _logReader.Read()) { SaveLogEntry(logEntry); } }
public IEnumerable <Event> Load() { Log log; Event ev; while (true) { try { log = logReader.Read(); } catch (Exception ex) { this.Log(ex); break; } if (log == null) { yield break; } if (!Try(() => logParser.Parse(log)).OrAlert(out ev, $"Failed to parse log at line {log.LineIndex}")) { continue; } if (ev == null) { continue; } yield return(ev); } }
public void ProcessLogs() { foreach (var logEntry in _logImporter.Read()) { SaveLogEntry(logEntry); } }
public void ImportLog(string fileName) { foreach (var logEntry in _logReader.Read()) { _logSaver.Save(logEntry); } }
/// <summary> /// Reads all Logged Errors from the Log Store. /// </summary> /// <returns>IReadonlyCollection</returns> public static IReadOnlyCollection <Error> Read() { try { return(LogReader.Read()); } catch { return(null); } }
public static void ReadBig(this ILogReader reader, Stream writeToStream, long checkpointSize) { var blockSize = 1024 * 1024; var buffer = new byte[blockSize]; while (checkpointSize > 0) { int bytesRead; if (checkpointSize >= blockSize) { bytesRead = reader.Read(buffer, 0, blockSize); } else { bytesRead = reader.Read(buffer, 0, (int)checkpointSize); } writeToStream.Write(buffer, 0, bytesRead); checkpointSize -= bytesRead; } }
//public ParserType1(SimpleUnitSample.Tests.Fakes.FakeLogReader fakeLogReader) //{ // this.fakeLogReader = fakeLogReader; //} public List <LogEntry> Parse(string path) { // var logReader = new LogReader(); var resultLines = logReader.Read(path); // [Info: 05:29:32 25.05.18] #RestartWindowsServiceAction.Restart finished, elapsed 00:00:02.2887519. //[Info: 05:29:32 25.05.18] #RestartWindowsServiceAction.Restart started. //[Info: 05:29:32 25.05.18] // Restarting EndurDealLifecycleService on ENDAPP82QA //[Info: 05:29:35 25.05.18] #RestartWindowsServiceAction.Restart finished, elapsed 00:00:03.2137709. return(resultLines.Select(item => new LogEntry { level = GetLogEntryLevels(item), timeStamp = GetTimeStamp(item), message = GetMessage(item) } ).ToList()); }
public void Send() { var configvalue = ConfigurationManager.AppSettings["PROTECTED_DailyErrorLogMail"]; configvalue = Regex.Replace(configvalue, @"\s+", ""); var receivers = configvalue.Split(','); var webLines = new List <string>(); var dbupdaterLines = new List <string>(); var dmzLines = new List <string>(); var mailLines = new List <string>(); try { webLines = _logReader.Read("C:\\logs\\os2eindberetning\\admin\\web.log"); dbupdaterLines = _logReader.Read("C:\\logs\\os2eindberetning\\admin\\dbupdater.log"); dmzLines = _logReader.Read("C:\\logs\\os2eindberetning\\admin\\dmz.log"); mailLines = _logReader.Read("C:\\logs\\os2eindberetning\\admin\\mail.log"); } catch (Exception ex) { _logger.Error($"{GetType().Name}, Send(), Error when trying to read from an admin log file", ex); throw ex; } var webMessage = String.Join(Environment.NewLine, _logParser.Messages(webLines, DateTime.Now.AddDays(-1))); var dbupdaterMessage = String.Join(Environment.NewLine, _logParser.Messages(dbupdaterLines, DateTime.Now.AddDays(-1))); var dmzMessage = String.Join(Environment.NewLine, _logParser.Messages(dmzLines, DateTime.Now.AddDays(-1))); var mailMessage = String.Join(Environment.NewLine, _logParser.Messages(mailLines, DateTime.Now.AddDays(-1))); var newLine = System.Environment.NewLine; var result = ""; // Only add each header if there are log messages in that category. if (webMessage.Any()) { result += "Web:" + newLine + newLine + webMessage + newLine + newLine; } if (dbupdaterMessage.Any()) { result += "DBUpdater:" + newLine + newLine + webMessage + newLine + newLine; } if (dmzMessage.Any()) { result += "DMZ: " + newLine + newLine + dmzMessage + newLine + newLine; } if (mailMessage.Any()) { result += "Mail: " + newLine + newLine + mailMessage; } if (result == "") { result = "Ingen fejl registreret"; } foreach (var receiver in receivers) { _mailSender.SendMail(receiver, "Log", result); } }
public void ProcessLogs() { List <LogEntry> logEntries = _logReader.Read(); // Process somehow }
/// <summary> /// Will copy all logs, which returns <b>true</b> from the <paramref name="logEntryFilterPredicate"/> function, from the <paramref name="log"/> and write them to a text file with the <paramref name="filename"/> in the given <paramref name="fileStore"/>. /// </summary> /// <remarks> /// <code> /// // The following characters are encoded into, and decoded from, the following: /// // Percent (%) %<25> /// // Semicolon (;) %<3B> /// // Double-Quote (") %<22> /// // Newline ( ) %<0D> /// </code> /// </remarks> /// <param name="log">The logger to read log from.</param> /// <param name="fileStore">The file store to write the log file to.</param> /// <param name="filename">The name of the file in the file store to write the logs to.</param> /// <param name="writeLogEntriesUsingLocalTime">Sets whether the date is written to the log relative to UTC or the local computer's timezone.</param> /// <param name="truncateLogArchive">Sets whether the <paramref name="fileStore"/> will be automatically truncated.</param> /// <param name="truncateLogArchiveMaximumFiles">The total number of files allowed in the <paramref name="fileStore"/> before auto truncation is performed.</param> /// <param name="truncateLogArchivePercentageToRemove">The percentage of log archive files to remove once <paramref name="truncateLogArchiveMaximumFiles"/> has been exceeded.</param> /// <param name="logEntryFilterPredicate">The <see cref="Func{T, TResult}"/> should return <b>true</b> to write the log to the archive file; return <b>false</b> to skip writing the log.</param> /// <returns>The number of logs written to the log file.</returns> public static int ArchiveLogs(ILogReader log, FileStorage.IFileStore fileStore, string filename, bool writeLogEntriesUsingLocalTime, bool truncateLogArchive, int truncateLogArchiveMaximumFiles, double truncateLogArchivePercentageToRemove, Func <ILogEntry, bool> logEntryFilterPredicate) { if (log == null) { throw new ArgumentNullException(nameof(log)); } if (fileStore == null) { throw new ArgumentNullException(nameof(fileStore)); } if (string.IsNullOrWhiteSpace(filename)) { throw new ArgumentNullException(nameof(filename)); } if ((truncateLogArchivePercentageToRemove < 0) || (truncateLogArchivePercentageToRemove > 1)) { throw new ArgumentOutOfRangeException(nameof(truncateLogArchivePercentageToRemove), $"Parameter truncateLogArchivePercentageToRemove must be between 0.0 and 1.0. Value={truncateLogArchivePercentageToRemove}"); } if (logEntryFilterPredicate == null) { throw new ArgumentNullException(nameof(logEntryFilterPredicate)); } // var archivedLogs = 0; // copy logs from the logger to the temp file var tempFilename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); lock (log.SyncObject) { using (var sw = new System.IO.StreamWriter(tempFilename, false)) { foreach (var entry in from x in log.Read() orderby x.Timestamp ascending select x) { if ((entry != null) && (logEntryFilterPredicate(entry))) { sw.WriteLine(FormatLogLine(entry, writeLogEntriesUsingLocalTime)); ++archivedLogs; } } } } if (archivedLogs > 0) { // copy temp file into FileStore fileStore.Add(filename, tempFilename, DateTime.UtcNow, 0); if (truncateLogArchive) { TruncateArchiveFileStore(fileStore, truncateLogArchiveMaximumFiles, truncateLogArchivePercentageToRemove); } fileStore.Save(true); } // delete temp file System.IO.File.Delete(tempFilename); // return number of archived logs return(archivedLogs); }