static LogParser() { var parsers = new List <LogSectionParser>(LogSections.Count); foreach (var sectionDescription in LogSections) { var parser = new LogSectionParser { OnLineCheckAsync = sectionDescription.OnNewLineAsync ?? ((l, s) => Task.CompletedTask), OnSectionEnd = sectionDescription.OnSectionEnd, EndTrigger = sectionDescription.EndTrigger.Select(s => s.ToLatin8BitEncoding()).ToArray(), }; // the idea here is to construct Aho-Corasick parser that will look for any data marker and run the associated regex to extract the data into state if (sectionDescription.Extractors?.Count > 0) { var act = new AhoCorasickDoubleArrayTrie <Action <string, LogParseState> >(sectionDescription.Extractors.Select(extractorPair => new SectionAction( extractorPair.Key.ToLatin8BitEncoding(), (buffer, state) => { #if DEBUG state.ExtractorHitStats.TryGetValue(extractorPair.Key, out var stat); state.ExtractorHitStats[extractorPair.Key] = stat + 1; #endif OnExtractorHit(buffer, extractorPair.Key, extractorPair.Value, state); }) ), true); parser.OnExtract = (line, buffer, state) => { act.ParseText(line, h => { h.Value(buffer, state); }); }; } parsers.Add(parser); } SectionParsers = parsers.AsReadOnly(); }
static LogParser() { var parsers = new List <LogSectionParser>(LogSections.Count); foreach (var sectionDescription in LogSections) { var parser = new LogSectionParser { OnSectionEnd = sectionDescription.OnSectionEnd, EndTrigger = sectionDescription.EndTrigger.Select(s => s.ToLatin8BitEncoding()).ToArray(), }; // the idea here is to construct Aho-Corasick parser that will look for any data marker and run the associated regex to extract the data into state if (sectionDescription.Extractors.Count > 0) { var act = new AhoCorasickDoubleArrayTrie <Action <string, LogParseState> >(sectionDescription.Extractors.Select(extractorPair => new SectionAction( extractorPair.Key.ToLatin8BitEncoding(), (buffer, state) => { #if DEBUG var timer = System.Diagnostics.Stopwatch.StartNew(); #endif OnExtractorHit(buffer, extractorPair.Key, extractorPair.Value, state); #if DEBUG timer.Stop(); lock (state.ExtractorHitStats) { state.ExtractorHitStats.TryGetValue(extractorPair.Key, out var stat); state.ExtractorHitStats[extractorPair.Key] = (stat.count + 1, stat.regexTime + timer.ElapsedTicks); } #endif })