private void ReportLogEntryHelper(string message, XmlLoaderLoggerEntry.EntryType entryType, bool failToLoadFile = false) { string currentPath = ComputeCurrentXPath(); XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry(); entry.entryType = entryType; entry.filePath = this.FilePath; entry.xPath = currentPath; entry.message = message; if (failToLoadFile) { System.Management.Automation.Diagnostics.Assert(entryType == XmlLoaderLoggerEntry.EntryType.Error, "the entry type should be 'error' when a file cannot be loaded"); entry.failToLoadFile = true; } _logger.LogEntry(entry); if (entryType == XmlLoaderLoggerEntry.EntryType.Error) { _currentErrorCount++; if (_currentErrorCount >= _maxNumberOfErrors) { // we have to log a last error and then bail if (_maxNumberOfErrors > 1) { XmlLoaderLoggerEntry lastEntry = new XmlLoaderLoggerEntry(); lastEntry.entryType = XmlLoaderLoggerEntry.EntryType.Error; lastEntry.filePath = this.FilePath; lastEntry.xPath = currentPath; lastEntry.message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrors, FilePath); _logger.LogEntry(lastEntry); _currentErrorCount++; } // NOTE: this exception is an internal one, and it is caught // internally by the calling code. TooManyErrorsException e = new TooManyErrorsException(); e.errorCount = _currentErrorCount; throw e; } } }
private void ReportLogEntryHelper(string message, XmlLoaderLoggerEntry.EntryType entryType, bool failToLoadFile = false) { string str = this.ComputeCurrentXPath(); XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry { entryType = entryType, filePath = this.FilePath, xPath = str, message = message }; if (failToLoadFile) { entry.failToLoadFile = true; } this.logger.LogEntry(entry); if (entryType == XmlLoaderLoggerEntry.EntryType.Error) { this.currentErrorCount++; if (this.currentErrorCount >= this.maxNumberOfErrors) { if (this.maxNumberOfErrors > 1) { XmlLoaderLoggerEntry entry2 = new XmlLoaderLoggerEntry { entryType = XmlLoaderLoggerEntry.EntryType.Error, filePath = this.FilePath, xPath = str, message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrors, this.FilePath) }; this.logger.LogEntry(entry2); this.currentErrorCount++; } TooManyErrorsException exception = new TooManyErrorsException { errorCount = this.currentErrorCount }; throw exception; } } }