private List <MessageTrackingLogEntry> ReadLogsFromCursor(LogSearchCursor cursor, TrackingEventBudget eventBudget) { List <MessageTrackingLogEntry> list = new List <MessageTrackingLogEntry>(); while (cursor.MoveNext()) { MessageTrackingLogEntry messageTrackingLogEntry; if (MessageTrackingLogEntry.TryCreateFromCursor(cursor, this.server, this.context.Errors, out messageTrackingLogEntry)) { if (list.Count % ServerCache.Instance.RowsBeforeTimeBudgetCheck == 0) { eventBudget.TestDelayOperation("GetRpcsBeforeDelay"); eventBudget.CheckTimeBudget(); } list.Add(messageTrackingLogEntry); if (messageTrackingLogEntry.RecipientAddresses != null) { eventBudget.IncrementBy((uint)messageTrackingLogEntry.RecipientAddresses.Length); } else { eventBudget.IncrementBy(1U); } } } return(list); }
private List <MessageTrackingLogEntry> ReadLogs(RpcReason rpcReason, string logFilePrefix, ProxyAddressCollection senderProxyAddresses, string messageId, DateTime startTime, DateTime endTime, TrackingEventBudget eventBudget) { Exception ex = null; int num = 0; List <MessageTrackingLogEntry> list = null; bool flag = !string.IsNullOrEmpty(messageId); bool flag2 = senderProxyAddresses != null; if (flag && flag2) { throw new InvalidOperationException("Cannot get logs with both message id and sender address criteria"); } if (rpcReason == RpcReason.None) { InfoWorkerMessageTrackingPerformanceCounters.GetMessageTrackingReportQueries.Increment(); } else { InfoWorkerMessageTrackingPerformanceCounters.SearchMessageTrackingReportQueries.Increment(); } try { this.context.DiagnosticsContext.LogRpcStart(this.server, rpcReason); using (LogSearchCursor cursor = TrackingSearch.GetCursor(this.server, this.version, logFilePrefix, messageId, senderProxyAddresses, startTime, endTime)) { list = this.ReadLogsFromCursor(cursor, eventBudget); } } catch (LogSearchException ex2) { ex = ex2; num = ex2.ErrorCode; } catch (RpcException ex3) { ex = ex3; num = ex3.ErrorCode; } finally { this.context.DiagnosticsContext.LogRpcEnd(ex, (list == null) ? 0 : list.Count); } if (ex != null) { TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Error reading from log-search RPC server for {0}: {1}, ErrorCode: {2}, Exception: {3}", new object[] { flag ? "message id" : "sender", flag ? messageId : senderProxyAddresses[0].ToString(), num, ex }); TrackingTransientException.AddAndRaiseETX(this.context.Errors, ErrorCode.LogSearchConnection, this.server, ex.ToString()); } return(list); }
public static bool TryCreateFromCursor(LogSearchCursor cursor, string server, TrackingErrorCollection errors, out MessageTrackingLogEntry entry) { entry = null; MessageTrackingLogRow messageTrackingLogRow; if (MessageTrackingLogRow.TryRead(server, cursor, MessageTrackingLogEntry.allRows, errors, out messageTrackingLogRow)) { entry = new MessageTrackingLogEntry(messageTrackingLogRow); return(true); } return(false); }
protected override void WriteResult(LogSearchCursor cursor) { object field = cursor.GetField(0); if (!(field is DateTime)) { return; } MessageTrackingEvent messageTrackingEvent = new MessageTrackingEvent(); messageTrackingEvent.Timestamp = ((DateTime)field).ToLocalTime(); messageTrackingEvent.ClientIp = (cursor.GetField(1) as string); messageTrackingEvent.ClientHostname = (string)cursor.GetField(2); messageTrackingEvent.ServerIp = (cursor.GetField(3) as string); messageTrackingEvent.ServerHostname = (cursor.GetField(4) as string); messageTrackingEvent.SourceContext = (cursor.GetField(5) as string); messageTrackingEvent.ConnectorId = (cursor.GetField(6) as string); messageTrackingEvent.Source = (cursor.GetField(7) as string); messageTrackingEvent.EventId = (cursor.GetField(8) as string); messageTrackingEvent.InternalMessageId = (cursor.GetField(9) as string); messageTrackingEvent.MessageId = (cursor.GetField(10) as string); messageTrackingEvent.Recipients = (cursor.GetField(12) as string[]); this.RedactPiiStringArrayIfNeeded(messageTrackingEvent.Recipients); messageTrackingEvent.RecipientStatus = (cursor.GetField(13) as string[]); if (messageTrackingEvent.EventId == "DELIVER" || messageTrackingEvent.EventId == "DUPLICATEDELIVER") { this.RedactPiiStringArrayIfNeeded(messageTrackingEvent.RecipientStatus); } messageTrackingEvent.TotalBytes = GetMessageTrackingLog.Unbox <int>(cursor.GetField(14)); messageTrackingEvent.RecipientCount = GetMessageTrackingLog.Unbox <int>(cursor.GetField(15)); messageTrackingEvent.RelatedRecipientAddress = this.RedactPiiStringIfNeeded(cursor.GetField(16) as string, false); messageTrackingEvent.Reference = (cursor.GetField(17) as string[]); if (messageTrackingEvent.Reference != null && messageTrackingEvent.Reference.Length == 1 && string.IsNullOrEmpty(messageTrackingEvent.Reference[0])) { messageTrackingEvent.Reference = null; } messageTrackingEvent.MessageSubject = this.RedactPiiStringIfNeeded(cursor.GetField(18) as string, true); messageTrackingEvent.Sender = this.RedactPiiStringIfNeeded(cursor.GetField(19) as string, false); messageTrackingEvent.ReturnPath = this.RedactPiiStringIfNeeded(cursor.GetField(20) as string, false); messageTrackingEvent.Directionality = (cursor.GetField(22) as string); messageTrackingEvent.TenantId = (cursor.GetField(23) as string); messageTrackingEvent.OriginalClientIp = (cursor.GetField(24) as string); messageTrackingEvent.MessageInfo = (cursor.GetField(21) as string); messageTrackingEvent.EventData = (cursor.GetField(26) as KeyValuePair <string, object>[]); if (base.NeedSuppressingPiiData) { Utils.RedactEventData(messageTrackingEvent.EventData, GetMessageTrackingLog.EventDataKeyToRedact, this); } GetMessageTrackingLog.CalculateLatencyProperties(messageTrackingEvent); base.WriteObject(messageTrackingEvent); }
public static bool TryRead(string server, LogSearchCursor cursor, BitArray fieldsToGet, TrackingErrorCollection errors, out MessageTrackingLogRow logEntry) { logEntry = null; MessageTrackingLogRow messageTrackingLogRow = new MessageTrackingLogRow(); messageTrackingLogRow.serverFqdn = server; for (int i = 0; i < fieldsToGet.Length; i++) { if (fieldsToGet[i]) { object obj = null; Exception ex = null; try { obj = cursor.GetField(i); } catch (LogSearchException ex2) { ex = ex2; int errorCode = ex2.ErrorCode; } catch (RpcException ex3) { ex = ex3; int errorCode2 = ex3.ErrorCode; } if (ex != null) { TrackingTransientException.AddAndRaiseETX(errors, ErrorCode.LogSearchConnection, server, ex.ToString()); } if (obj != null && obj.GetType() != MessageTrackingSchema.MessageTrackingEvent.Fields[i].Type) { throw new InvalidOperationException(string.Format("Schema for column {0} in message-tracking is of sync with tasks", i)); } if (!MessageTrackingLogRow.ValidateField(messageTrackingLogRow, i, obj, errors)) { return(false); } messageTrackingLogRow.columns[i] = cursor.GetField(i); messageTrackingLogRow.validColumns[i] = true; } } if (fieldsToGet[8] && (messageTrackingLogRow.EventId == MessageTrackingEvent.EXPAND || messageTrackingLogRow.EventId == MessageTrackingEvent.RESOLVE)) { MessageTrackingLogRow.SmtpAddressValidatorWithNull(messageTrackingLogRow.RelatedRecipientAddress); } logEntry = messageTrackingLogRow; return(true); }
protected override void InternalProcessRecord() { LogQuery logQuery = new LogQuery(); logQuery.Filter = this.GetCondition(); logQuery.Beginning = this.start.ToUniversalTime(); logQuery.End = this.end.ToUniversalTime(); uint num = 0U; try { using (LogSearchCursor logSearchCursor = new LogSearchCursor(this.table, this.serverObject.Fqdn, this.serverObject.AdminDisplayVersion, this.logName, logQuery, this)) { this.cursor = logSearchCursor; while (logSearchCursor.MoveNext()) { if (!this.resultSize.IsUnlimited && num >= this.resultSize.Value) { this.WriteWarning(Strings.WarningMoreResultsAvailable); break; } num += 1U; this.WriteResult(logSearchCursor); } } } catch (LogSearchException ex) { if (!base.Stopping || ex.ErrorCode != LogSearchErrorCode.LOGSEARCH_E_SESSION_CANCELED) { this.WriteLogSearchError(ex); } } catch (RpcException e) { this.WriteRpcError(e); } }
protected abstract void WriteResult(LogSearchCursor cursor);