public (bool, EventDataDisplayItem) Parse(string eventLine) { IDictionary <string, string> parseParts = ParseLine(eventLine); if (parseParts.Count != NUM_PARSE_PARTS) { return(false, null); // not something for the activity report } EventDataDisplayItem eddi = new EventDataDisplayItem( FormatEventCode(parseParts[EVENT_CODE]) , FomratMessage(parseParts[MESSAGE], parseParts[URL]) , FormatDate(parseParts[DATE]) ); return(true, eddi); }
public List <EventDataDisplayItem> GetEventsForDay(DateTime date) { List <EventDataDisplayItem> events = new List <EventDataDisplayItem>(); bool isPreviousEvent = false; StringBuilder stackTrace = new StringBuilder(); // add in the stacktrace to the last event void UpdatePreviousEvent() { EventDataDisplayItem existingEddi = events[events.Count - 1]; var completeEddi = new EventDataDisplayItem( existingEddi.EventCode , existingEddi.HtmlMessage + stackTrace , existingEddi.Date); events[events.Count - 1] = completeEddi; stackTrace.Clear(); } try { // process all the lines in the log for the given date // ignore info not related to DasBlog events i.e. Microsoft logging // and aggregate stack traces for dasBlog events with the event line using (var repo = repoFactory.GetRepo()) { foreach (var line in repo.GetEventLines(date)) { char[] chars = line.ToCharArray(); if (chars.Length > 0 && !Char.IsDigit(chars[0])) { goto stack_trace; } // any line not starting with a date is treated as a stack trace frome (bool success, EventDataDisplayItem eddi) = parser.Parse(line); if (success) { goto event_line; } goto non_event_line; // any line that could not be parsed is assumed not to be a dasblog event // and is ignored event_line: if (isPreviousEvent) // previous event still in progress { UpdatePreviousEvent(); } events.Add(eddi); isPreviousEvent = true; continue; non_event_line: if (isPreviousEvent) // previous event still in progress { UpdatePreviousEvent(); } isPreviousEvent = false; continue; stack_trace: if (isPreviousEvent) { stackTrace.Append("<br>"); stackTrace.Append(line); } continue; } } if (isPreviousEvent) { UpdatePreviousEvent(); } } catch (Exception e) { LoggedException le = new LoggedException("file failure", e); logger.LogError(new EventDataItem(EventCodes.Error, null , "Failed to process the log file for {date}", date.ToShortDateString()) , le); throw le; } return(events); }