internal MessageLogTraceRecord(Stream stream, MessageLoggingSource source) : this(source) { this.type = null; System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); StreamReader streamReader = new StreamReader(stream); int chunkSize = 4096; char[] buffer = DiagnosticUtility.Utility.AllocateCharArray(chunkSize); int count = MessageLogger.MaxMessageSize; if (-1 == count) { count = 4096; //Can't buffer potentially unbounded stream, let's get 4K hoping it will help } while (count > 0) { int charsRead = streamReader.Read(buffer, 0, chunkSize); if (charsRead == 0) { break; } int charsToAppend = count < charsRead ? count : charsRead; stringBuilder.Append(buffer, 0, charsToAppend); count -= charsRead; } streamReader.Close(); this.messageString = stringBuilder.ToString(); }
static void LogMessageImpl(ref Message message, XmlReader reader, MessageLoggingSource source) { ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? TraceUtility.ExtractActivity(message) : null; using (ServiceModelActivity.BoundOperation(activity)) { if (ShouldLogMessages(source) && (MessageLogger.numberOfMessagesToLog > 0 || MessageLogger.numberOfMessagesToLog == MessageLogger.Unlimited)) { bool lastChance = (source & MessageLoggingSource.LastChance) != 0 || (source & MessageLoggingSource.TransportSend) != 0; source &= ~MessageLoggingSource.LastChance; // MessageLogger doesn't log AddressingVersion.None in the encoder since we want to make sure we log // as much of the message as possible. So let the Transport log later. if ((lastChance || message is NullMessage || message.Version.Addressing != AddressingVersion.None) && MatchFilters(message, source)) { if (MessageLogger.numberOfMessagesToLog == MessageLogger.Unlimited || MessageLogger.numberOfMessagesToLog > 0) { MessageLogTraceRecord record = new MessageLogTraceRecord(ref message, reader, source, MessageLogger.LogMessageBody); LogInternal(record); } } } } }
internal MessageLogTraceRecord(ArraySegment<byte> buffer, MessageLoggingSource source) : this(source) { this.type = null; this.messageString = System.Text.Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count); }
private static void LogMessageImpl(ref Message message, XmlReader reader, MessageLoggingSource source) { ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? TraceUtility.ExtractActivity(message) : null; using (ServiceModelActivity.BoundOperation(activity)) { if (ShouldLogMessages(source) && ((numberOfMessagesToLog > 0) || (numberOfMessagesToLog == -1))) { bool flag = ((source & MessageLoggingSource.LastChance) != MessageLoggingSource.None) || ((source & MessageLoggingSource.TransportSend) != MessageLoggingSource.None); source &= ~MessageLoggingSource.LastChance; if (((flag || (message is NullMessage)) || (message.Version.Addressing != AddressingVersion.None)) && (MatchFilters(message, source) && ((numberOfMessagesToLog == -1) || (numberOfMessagesToLog > 0)))) { MessageLogTraceRecord record = new MessageLogTraceRecord(ref message, reader, source, LogMessageBody); LogInternal(record); } } } }
MessageLogTraceRecord(MessageLoggingSource source) { this.source = source; this.timestamp = DateTime.Now; }
internal MessageLogTraceRecord(string message, MessageLoggingSource source) : this(source) { this.type = null; this.messageString = message; }
static void LogInternal(MessageLoggingSource source, object data) { if ((source & MessageLoggingSource.Malformed) != 0) { if (TD.MessageLogWarningIsEnabled() && !TD.MessageLogWarning(data.ToString())) { if (TD.MessageLogEventSizeExceededIsEnabled()) { TD.MessageLogEventSizeExceeded(); } } } else { if (TD.MessageLogInfoIsEnabled() && !TD.MessageLogInfo(data.ToString())) { if (TD.MessageLogEventSizeExceededIsEnabled()) { TD.MessageLogEventSizeExceeded(); } } } if (MessageLogger.MessageTraceSource != null) { MessageLogger.MessageTraceSource.TraceData(TraceEventType.Information, 0, data); } IncrementLoggedMessagesCount(data); }
static void ThrowIfNotMalformed(MessageLoggingSource source) { if ((source & MessageLoggingSource.Malformed) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.OnlyMalformedMessagesAreSupported), "source")); } }
internal static void LogMessage(ArraySegment<byte> buffer, MessageLoggingSource source) { try { ThrowIfNotMalformed(source); if (ShouldLogMessages(source)) { LogInternal(new MessageLogTraceRecord(buffer, source)); } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) throw; FailedToLogMessage(e); } }
internal static void LogMessage(ref Message message, MessageLoggingSource source) { LogMessage(ref message, null, source); }
internal static void LogMessage(ref Message message, XmlReader reader, MessageLoggingSource source) { try { if (ShouldLogMessages(source)) { LogMessageImpl(ref message, reader, source); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } FailedToLogMessage(exception); } }
internal static void LogMessage(MessageLoggingSource source, string data) { try { if (ShouldLogMessages(MessageLoggingSource.Malformed)) { LogInternal(source, data); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } FailedToLogMessage(exception); } }
internal static void LogMessage(ArraySegment<byte> buffer, MessageLoggingSource source) { try { ThrowIfNotMalformed(source); if (ShouldLogMessages(source)) { LogInternal(new MessageLogTraceRecord(buffer, source)); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } FailedToLogMessage(exception); } }
internal static void LogMessage(Stream stream, MessageLoggingSource source) { try { ThrowIfNotMalformed(source); if (ShouldLogMessages(source)) { LogInternal(new MessageLogTraceRecord(stream, source)); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } FailedToLogMessage(exception); } }
internal static void LogMessage(ref Channels.Message message, Xml.XmlDictionaryReader xmlDictionaryReader, MessageLoggingSource messageLoggingSource) { throw NotImplemented.ByDesign; }
internal static void LogMessage(ArraySegment<byte> arraySegment, MessageLoggingSource messageLoggingSource) { throw NotImplemented.ByDesign; }
internal static void LogMessage(ref Channels.Message message, MessageLoggingSource messageLoggingSource) { throw NotImplemented.ByDesign; }
private static bool MatchFilters(Message message, MessageLoggingSource source) { bool flag = true; if (FilterMessages && ((source & MessageLoggingSource.Malformed) == MessageLoggingSource.None)) { flag = false; List<XPathMessageFilter> list = new List<XPathMessageFilter>(); lock (syncObject) { foreach (XPathMessageFilter filter in Filters) { try { if (filter.Match(message)) { flag = true; break; } } catch (FilterInvalidBodyAccessException) { list.Add(filter); } catch (MessageFilterException exception) { if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, 0x20008, System.ServiceModel.SR.GetString("TraceCodeFilterNotMatchedNodeQuotaExceeded"), (Exception) exception, message); } } } foreach (XPathMessageFilter filter2 in list) { Filters.Remove(filter2); PlainXmlWriter writer = new PlainXmlWriter(); filter2.WriteXPathTo(writer, null, "filter", null, true); DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.MessageLogging, (EventLogEventId) (-1073610746), new string[] { writer.Navigator.ToString() }); } if (FilterCount == 0) { flag = true; } } } return flag; }
internal static void LogMessage(ref Message message, XmlReader reader, MessageLoggingSource source) { Fx.Assert(null != message, ""); try { if (ShouldLogMessages(source)) { LogMessageImpl(ref message, reader, source); } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) throw; FailedToLogMessage(e); } }
private static bool ShouldLogMessages(MessageLoggingSource source) { if ((source & Sources) == MessageLoggingSource.None) { return false; } return (((MessageTraceSource != null) || (((source & MessageLoggingSource.Malformed) != MessageLoggingSource.None) && TD.MessageLogWarningIsEnabled())) || TD.MessageLogInfoIsEnabled()); }
private static bool ShouldProcessAudit(MessageLoggingSource source, bool turningOn) { if (turningOn) { return (sources == MessageLoggingSource.None); } return (sources == source); }
static bool MatchFilters(Message message, MessageLoggingSource source) { bool result = true; if (MessageLogger.FilterMessages && (source & MessageLoggingSource.Malformed) == 0) { result = false; List<XPathMessageFilter> filtersToRemove = new List<XPathMessageFilter>(); lock (MessageLogger.syncObject) { foreach (XPathMessageFilter filter in MessageLogger.Filters) { try { if (filter.Match(message)) { result = true; break; } } catch (FilterInvalidBodyAccessException) { filtersToRemove.Add(filter); } catch (MessageFilterException e) { if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.FilterNotMatchedNodeQuotaExceeded, SR.GetString(SR.TraceCodeFilterNotMatchedNodeQuotaExceeded), e, message); } } } foreach (XPathMessageFilter filter in filtersToRemove) { MessageLogger.Filters.Remove(filter); PlainXmlWriter writer = new PlainXmlWriter(); filter.WriteXPathTo(writer, null, ConfigurationStrings.Filter, null, true); DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.MessageLogging, (uint)System.Runtime.Diagnostics.EventLogEventId.RemovedBadFilter, writer.Navigator.ToString()); } if (MessageLogger.FilterCount == 0) { result = true; } } } return result; }
private static void ThrowIfNotMalformed(MessageLoggingSource source) { if ((source & MessageLoggingSource.Malformed) == MessageLoggingSource.None) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("OnlyMalformedMessagesAreSupported"), "source")); } }
static bool ShouldProcessAudit(MessageLoggingSource source, bool turningOn) { bool result = false; if (turningOn) { result = MessageLogger.sources == MessageLoggingSource.None; } else { result = MessageLogger.sources == source; } return result; }
internal static void LogMessage(Stream stream, MessageLoggingSource messageLoggingSource) { throw NotImplemented.ByDesign; }
internal MessageLogTraceRecord(ArraySegment <byte> buffer, MessageLoggingSource source) : this(source) { this.type = null; this.messageString = System.Text.Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count); }
internal static void LogMessage(ArraySegment <byte> arraySegment, MessageLoggingSource messageLoggingSource) { throw NotImplemented.ByDesign; }
internal MessageLogTraceRecord(ref Message message, XmlReader reader, MessageLoggingSource source, bool logMessageBody) : this(source) { Fx.Assert(message != null, ""); MessageBuffer buffer = null; try { this.logMessageBody = logMessageBody; this.message = message; this.reader = reader; this.type = message.GetType(); } finally { if (buffer != null) { buffer.Close(); } } }
static bool ShouldLogMessages(MessageLoggingSource source) { return (source & MessageLogger.Sources) != 0 && ((MessageLogger.MessageTraceSource != null) || ((source & MessageLoggingSource.Malformed) != 0 && TD.MessageLogWarningIsEnabled()) || TD.MessageLogInfoIsEnabled()); }
internal static void LogMessage(MessageLoggingSource source, string data) { try { if (ShouldLogMessages(MessageLoggingSource.Malformed)) { LogInternal(source, data); } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) throw; FailedToLogMessage(e); } }