/// <summary> /// Triggered when a new entry is added in the debug log. /// </summary> /// <param name="message">Message string.</param> /// <param name="verbosity">Verbosity level defining message importance.</param> /// <param name="category">Category of the sub-system reporting the message.</param> private void OnEntryAdded(string message, LogVerbosity verbosity, int category) { // Check if compiler message or reported exception, otherwise parse it as a normal log message ParsedLogEntry logEntry = ScriptCodeManager.ParseCompilerMessage(message); if (logEntry == null) { logEntry = Debug.ParseExceptionMessage(message); } if (logEntry == null) { logEntry = Debug.ParseLogMessage(message); } ConsoleEntryData newEntry = new ConsoleEntryData(); newEntry.verbosity = verbosity; newEntry.category = category; newEntry.callstack = logEntry.callstack; newEntry.message = logEntry.message; entries.Add(newEntry); if (DoesFilterMatch(verbosity)) { listView.AddEntry(newEntry); filteredEntries.Add(newEntry); } }
/// <summary> /// Triggered when a new entry is added in the debug log. /// </summary> /// <param name="type">Type of the message.</param> /// <param name="message">Message string.</param> private void OnEntryAdded(DebugMessageType type, string message) { // Check if compiler message or reported exception, otherwise parse it as a normal log message ParsedLogEntry logEntry = ScriptCodeManager.ParseCompilerMessage(message); if (logEntry == null) { logEntry = Debug.ParseExceptionMessage(message); } if (logEntry == null) { logEntry = Debug.ParseLogMessage(message); } ConsoleEntryData newEntry = new ConsoleEntryData(); newEntry.type = type; newEntry.callstack = logEntry.callstack; newEntry.message = logEntry.message; entries.Add(newEntry); if (DoesFilterMatch(type)) { listView.AddEntry(newEntry); filteredEntries.Add(newEntry); } }
/// <summary> /// Parses a managed exception message and outputs a data object with a separate message and callstack entries. /// </summary> /// <param name="message">Message to parse.</param> /// <returns>Parsed log message.</returns> public static ParsedLogEntry ParseExceptionMessage(string message) { Regex headerRegex = new Regex(@"Managed exception: (.*)\n"); var headerMatch = headerRegex.Match(message); if (!headerMatch.Success) { return(null); } Regex regex = new Regex(@" at (.*) \[.*\] in (.*):(\d*)"); var matches = regex.Matches(message); ParsedLogEntry newEntry = new ParsedLogEntry(); newEntry.callstack = new CallStackEntry[matches.Count]; for (int i = 0; i < matches.Count; i++) { CallStackEntry callstackEntry = new CallStackEntry(); callstackEntry.method = matches[i].Groups[1].Value; callstackEntry.file = matches[i].Groups[2].Value; int.TryParse(matches[i].Groups[3].Value, out callstackEntry.line); newEntry.callstack[i] = callstackEntry; } newEntry.message = headerMatch.Groups[1].Value; return(newEntry); }
/// <summary> /// Parses a log message and outputs a data object with a separate message and callstack entries. If the message /// is not a valid compiler message null is returned. /// </summary> /// <param name="message">Message to parse.</param> /// <returns>Parsed log message or null if not a valid compiler message.</returns> public static ParsedLogEntry ParseCompilerMessage(string message) { // Note: If modifying FormMessage method make sure to update this one as well to match the formattting // Check for error Regex regex = new Regex(@"Compiler error: (.*)\n\tin (.*)\[(.*):.*\]"); var match = regex.Match(message); // Check for warning if (!match.Success) { regex = new Regex(@"Compiler warning: (.*)\n\tin (.*)\[(.*):.*\]"); match = regex.Match(message); } // No match if (!match.Success) return null; ParsedLogEntry entry = new ParsedLogEntry(); entry.callstack = new CallStackEntry[1]; entry.message = match.Groups[1].Value; CallStackEntry callstackEntry = new CallStackEntry(); callstackEntry.method = ""; callstackEntry.file = match.Groups[2].Value; int.TryParse(match.Groups[3].Value, out callstackEntry.line); entry.callstack[0] = callstackEntry; return entry; }
/// <summary> /// Parses a log message and outputs a data object with a separate message and callstack entries. If the message /// is not a valid compiler message null is returned. /// </summary> /// <param name="message">Message to parse.</param> /// <returns>Parsed log message or null if not a valid compiler message.</returns> public static ParsedLogEntry ParseCompilerMessage(string message) { // Note: If modifying FormMessage method make sure to update this one as well to match the formattting // Check for error Regex regex = new Regex(@"Compiler error: (.*)\n\tin (.*)\[(.*):.*\]"); var match = regex.Match(message); // Check for warning if (!match.Success) { regex = new Regex(@"Compiler warning: (.*)\n\tin (.*)\[(.*):.*\]"); match = regex.Match(message); } // No match if (!match.Success) { return(null); } ParsedLogEntry entry = new ParsedLogEntry(); entry.callstack = new CallStackEntry[1]; entry.message = match.Groups[1].Value; CallStackEntry callstackEntry = new CallStackEntry(); callstackEntry.method = ""; callstackEntry.file = match.Groups[2].Value; int.TryParse(match.Groups[3].Value, out callstackEntry.line); entry.callstack[0] = callstackEntry; return(entry); }
/// <summary> /// Parses a log message and outputs a data object with a separate message and callstack entries. /// </summary> /// <param name="message">Message to parse.</param> /// <returns>Parsed log message.</returns> public static ParsedLogEntry ParseLogMessage(string message) { // Note: If you are modifying GetStackTrace method make sure to also update this one to match the formattting int firstMatchIdx = -1; Regex regex = new Regex(@"\tat (.*) in (.*), line (\d*), column .*, namespace .*"); var matches = regex.Matches(message); ParsedLogEntry newEntry = new ParsedLogEntry(); newEntry.callstack = new CallStackEntry[matches.Count]; for (int i = 0; i < matches.Count; i++) { CallStackEntry callstackEntry = new CallStackEntry(); callstackEntry.method = matches[i].Groups[1].Value; callstackEntry.file = matches[i].Groups[2].Value; int.TryParse(matches[i].Groups[3].Value, out callstackEntry.line); newEntry.callstack[i] = callstackEntry; if (firstMatchIdx == -1) { firstMatchIdx = matches[i].Index; } } if (firstMatchIdx != -1) { newEntry.message = message.Substring(0, firstMatchIdx); } else { newEntry.message = message; } return(newEntry); }
private void WriteLogToDb(ParsedLogEntry parsedLog) { using (var repository = this.repositoryFactory.CreateLogRepository()) { var fileToCheck = repository.FindFirst <File>(x => x.Path == parsedLog.Path); if (fileToCheck == null) { WebPageInfo pageInfo; try { pageInfo = webHelper.GetPageInfo(parsedLog.Path); fileToCheck = new File() { Path = parsedLog.Path, Size = pageInfo.Size, Title = pageInfo.Title, }; } catch { fileToCheck = new File() { Path = parsedLog.Path, }; } repository.Create(fileToCheck); } var ipInBytes = IpConverter.FromString(parsedLog.IpAddress); var ipToCheck = repository.FindFirst <Ip>(x => x.Address.SequenceEqual(ipInBytes)); if (ipToCheck == null) { var organization = webHelper.GetOrganizationNameByWhois(parsedLog.IpAddress); ipToCheck = new Ip() { Address = ipInBytes, OwnerName = organization, }; repository.Create(ipToCheck); } var logEntry = new LogEntry() { IpInfo = ipToCheck, FileInfo = fileToCheck, Method = parsedLog.Method, Amount = int.Parse(parsedLog.Amount), StatusCode = short.Parse(parsedLog.Status), Date = DateTimeOffset.ParseExact( parsedLog.Date, LogSettings.DateTimeOffsetPattern, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None), }; repository.Create(logEntry); try { repository.Save(); } catch { WriteLogToDb(parsedLog); return; } Interlocked.Increment(ref entriesProcessedCount); Interlocked.Exchange(ref progressPercent, ((double)entriesProcessedCount / entriesCount * 100)); } }