private static bool IsValidDotNetEntry( EventRecord eventLogRecord, ref FeedbackItemDotNetEntry dotNetEntry ) { if ( StringComparer.InvariantCultureIgnoreCase.Equals( eventLogRecord.ProviderName, DotNetProviderName ) && s_dotNetEventId.Contains(eventLogRecord.Id) ) { dotNetEntry = new FeedbackItemDotNetEntry(eventLogRecord); foreach (var app in VsRelatedExes) { if ( dotNetEntry.Data.IndexOf(app, StringComparison.InvariantCultureIgnoreCase) >= 0 ) { return(true); } } } return(false); }
internal static void TryWriteDotNetEntriesToFile(string filePath) { try { var dotNetEntries = new HashSet <FeedbackItemDotNetEntry>(); // We need to search in the Application Event Log, since that's where .NetRuntime logs entries var eventLogQuery = new EventLogQuery(EventLogName, PathType.LogName) { // Read events in descending order, so we can get either the last 5 entries or the past day of entries, whichever has a bigger count ReverseDirection = true }; var eventLogReader = new EventLogReader(eventLogQuery); EventRecord eventLogRecord; while ((eventLogRecord = eventLogReader.ReadEvent()) != null) { // We only want the last 5 entries or the past day of entries, whichever has a bigger count if (IsLastDayOrLastFiveRecentEntry(eventLogRecord, dotNetEntries.Count)) { // Filter the entries by .NetRuntime specific ones FeedbackItemDotNetEntry entry = null; if (IsValidDotNetEntry(eventLogRecord, ref entry)) { dotNetEntries.Add(entry); } } else { break; } } if (dotNetEntries.Any()) { var dotNetEntriesStringBuilder = new StringBuilder(); foreach (var entry in dotNetEntries) { dotNetEntriesStringBuilder.AppendLine( $"Event Time (UTC): {entry.EventTime}" ); dotNetEntriesStringBuilder.AppendLine($"Event ID: {entry.EventId}"); dotNetEntriesStringBuilder.AppendLine( $"Data: {entry.Data.Replace("\n", "\r\n")}" ); dotNetEntriesStringBuilder.AppendLine(); } File.WriteAllText(filePath, dotNetEntriesStringBuilder.ToString()); } } catch (Exception ex) { File.WriteAllText(filePath, ex.ToString()); } }