private void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source)
 {
     xml.WriteStartElement("TraceRecord");
     xml.WriteAttributeString("xmlns", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
     xml.WriteAttributeString("Severity", LookupSeverity(type));
     xml.WriteElementString("TraceIdentifier", msdnTraceCode);
     xml.WriteElementString("Description", description);
     xml.WriteElementString("AppDomain", this.AppDomainFriendlyName);
     if (source != null)
     {
         xml.WriteElementString("Source", CreateSourceString(source));
     }
     if (trace != null)
     {
         xml.WriteStartElement("ExtendedData");
         xml.WriteAttributeString("xmlns", trace.EventId);
         trace.WriteTo(xml);
         xml.WriteEndElement();
     }
     if (exception != null)
     {
         xml.WriteStartElement("Exception");
         this.AddExceptionToTraceString(xml, exception);
         xml.WriteEndElement();
     }
     xml.WriteEndElement();
 }
        private static void LogInternal(MessageLogTraceRecord record)
        {
            PlainXmlWriter writer = new PlainXmlWriter(MaxMessageSize);

            try
            {
                record.WriteTo(writer);
                writer.Close();
                TraceXPathNavigator data = writer.Navigator;
                if (((messageTraceSource != null) && !messageTraceSource.ShouldLogPii) || !LogKnownPii)
                {
                    data.RemovePii(PiiHeadersPaths);
                    if ((LogMessageBody && (record.Message != null)) && HasSecurityAction(record.Message))
                    {
                        data.RemovePii(PiiBodyPaths);
                    }
                }
                LogInternal(record.MessageLoggingSource, data);
            }
            catch (PlainXmlWriter.MaxSizeExceededException)
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, 0x2000b, System.ServiceModel.SR.GetString("TraceCodeMessageNotLoggedQuotaExceeded"), record.Message);
                }
            }
        }
        void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description,
                        TraceRecord trace, Exception exception, object source)
        {
            xml.WriteStartElement(DiagnosticStrings.TraceRecordTag);
            xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, LegacyDiagnosticTrace.TraceRecordVersion);
            xml.WriteAttributeString(DiagnosticStrings.SeverityTag, DiagnosticTraceBase.LookupSeverity(type));

            xml.WriteElementString(DiagnosticStrings.TraceCodeTag, msdnTraceCode);
            xml.WriteElementString(DiagnosticStrings.DescriptionTag, description);
            xml.WriteElementString(DiagnosticStrings.AppDomain, DiagnosticTraceBase.AppDomainFriendlyName);

            if (source != null)
            {
                xml.WriteElementString(DiagnosticStrings.SourceTag, CreateSourceString(source));
            }

            if (trace != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExtendedDataTag);
                xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, trace.EventId);

                trace.WriteTo(xml);

                xml.WriteEndElement();
            }

            if (exception != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExceptionTag);
                AddExceptionToTraceString(xml, exception);
                xml.WriteEndElement();
            }

            xml.WriteEndElement();
        }
        private void BuildTrace(TraceEventType type, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source, out TraceXPathNavigator navigator)
        {
            PlainXmlWriter xml = new PlainXmlWriter(0xffff);

            navigator = xml.Navigator;
            this.BuildTrace(xml, type, msdnTraceCode, description, trace, exception, source);
            if (!this.TraceSource.ShouldLogPii)
            {
                navigator.RemovePii(System.ServiceModel.Diagnostics.DiagnosticStrings.HeadersPaths);
            }
        }
Example #5
0
        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);
        }
        void BuildTrace(TraceEventType type, string msdnTraceCode, string description, TraceRecord trace,
                        Exception exception, object source, out TraceXPathNavigator navigator)
        {
            PlainXmlWriter xmlWriter = new PlainXmlWriter(LegacyDiagnosticTrace.MaxTraceSize);

            navigator = xmlWriter.Navigator;

            this.BuildTrace(xmlWriter, type, msdnTraceCode, description, trace, exception, source);

            if (!ShouldLogPii)
            {
                navigator.RemovePii(DiagnosticStrings.HeadersPaths);
            }
        }
 private static void FillAddressInfo(System.ServiceModel.Administration.EndpointInfo endpoint, IWmiInstance instance)
 {
     string[] info = new string[endpoint.Headers.Count];
     int num = 0;
     foreach (AddressHeader header in endpoint.Headers)
     {
         PlainXmlWriter writer = new PlainXmlWriter();
         header.WriteAddressHeader(writer);
         info[num++] = writer.ToString();
     }
     ProviderBase.FillCollectionInfo(info, instance, "AddressHeaders");
     instance.SetProperty("Address", (endpoint.Address == null) ? string.Empty : endpoint.Address.ToString());
     instance.SetProperty("ListenUri", (endpoint.ListenUri == null) ? string.Empty : endpoint.ListenUri.ToString());
     instance.SetProperty("AddressIdentity", (endpoint.Identity == null) ? string.Empty : endpoint.Identity.ToString());
 }
        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);
        }
Example #9
0
        static void LogInternal(MessageLogTraceRecord record)
        {
            Fx.Assert(null != record, "record cannot be null");

            PlainXmlWriter xmlWriter = new PlainXmlWriter(MessageLogger.MaxMessageSize);

            try
            {
                record.WriteTo(xmlWriter);
                xmlWriter.Close();
                TraceXPathNavigator navigator = xmlWriter.Navigator;

                if ((MessageLogger.messageTraceSource != null &&
                     !MessageLogger.messageTraceSource.ShouldLogPii) ||
                    !MessageLogger.LogKnownPii)
                {
                    navigator.RemovePii(MessageLogger.PiiHeadersPaths);
                    if (MessageLogger.LogMessageBody && null != record.Message)
                    {
                        if (HasSecurityAction(record.Message))
                        {
                            navigator.RemovePii(MessageLogger.PiiBodyPaths);
                        }
                    }
                }

                LogInternal(record.MessageLoggingSource, navigator);
            }
            catch (PlainXmlWriter.MaxSizeExceededException)
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.MessageNotLoggedQuotaExceeded,
                                            SR.GetString(SR.TraceCodeMessageNotLoggedQuotaExceeded), record.Message);
                }
            }
        }
 private void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source)
 {
     xml.WriteStartElement("TraceRecord");
     xml.WriteAttributeString("xmlns", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
     xml.WriteAttributeString("Severity", LookupSeverity(type));
     xml.WriteElementString("TraceIdentifier", msdnTraceCode);
     xml.WriteElementString("Description", description);
     xml.WriteElementString("AppDomain", this.AppDomainFriendlyName);
     if (source != null)
     {
         xml.WriteElementString("Source", CreateSourceString(source));
     }
     if (trace != null)
     {
         xml.WriteStartElement("ExtendedData");
         xml.WriteAttributeString("xmlns", trace.EventId);
         trace.WriteTo(xml);
         xml.WriteEndElement();
     }
     if (exception != null)
     {
         xml.WriteStartElement("Exception");
         this.AddExceptionToTraceString(xml, exception);
         xml.WriteEndElement();
     }
     xml.WriteEndElement();
 }
 private static void LogInternal(MessageLogTraceRecord record)
 {
     PlainXmlWriter writer = new PlainXmlWriter(MaxMessageSize);
     try
     {
         record.WriteTo(writer);
         writer.Close();
         TraceXPathNavigator data = writer.Navigator;
         if (((messageTraceSource != null) && !messageTraceSource.ShouldLogPii) || !LogKnownPii)
         {
             data.RemovePii(PiiHeadersPaths);
             if ((LogMessageBody && (record.Message != null)) && HasSecurityAction(record.Message))
             {
                 data.RemovePii(PiiBodyPaths);
             }
         }
         LogInternal(record.MessageLoggingSource, data);
     }
     catch (PlainXmlWriter.MaxSizeExceededException)
     {
         if (DiagnosticUtility.ShouldTraceWarning)
         {
             TraceUtility.TraceEvent(TraceEventType.Warning, 0x2000b, System.ServiceModel.SR.GetString("TraceCodeMessageNotLoggedQuotaExceeded"), record.Message);
         }
     }
 }
 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;
 }
 static void FillAddressInfo(EndpointInfo endpoint, IWmiInstance instance)
 {
     Fx.Assert(null != endpoint, "");
     Fx.Assert(null != instance, "");
     string[] headers = new string[endpoint.Headers.Count];
     int i = 0;
     foreach (AddressHeader header in endpoint.Headers)
     {
         PlainXmlWriter xmlWriter = new PlainXmlWriter();
         header.WriteAddressHeader(xmlWriter);
         headers[i++] = xmlWriter.ToString();
     }
     ProviderBase.FillCollectionInfo(headers, instance, AdministrationStrings.AddressHeaders);
     instance.SetProperty(AdministrationStrings.Address, endpoint.Address == null ? String.Empty : endpoint.Address.ToString());
     instance.SetProperty(AdministrationStrings.ListenUri, endpoint.ListenUri == null ? String.Empty : endpoint.ListenUri.ToString());
     instance.SetProperty(AdministrationStrings.Identity, endpoint.Identity == null ? String.Empty : endpoint.Identity.ToString());
 }
        void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description,
            TraceRecord trace, Exception exception, object source)
        {
            xml.WriteStartElement(DiagnosticStrings.TraceRecordTag);
            xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, LegacyDiagnosticTrace.TraceRecordVersion);
            xml.WriteAttributeString(DiagnosticStrings.SeverityTag, DiagnosticTraceBase.LookupSeverity(type));

            xml.WriteElementString(DiagnosticStrings.TraceCodeTag, msdnTraceCode);
            xml.WriteElementString(DiagnosticStrings.DescriptionTag, description);
            xml.WriteElementString(DiagnosticStrings.AppDomain, DiagnosticTraceBase.AppDomainFriendlyName);

            if (source != null)
            {
                xml.WriteElementString(DiagnosticStrings.SourceTag, CreateSourceString(source));
            }

            if (trace != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExtendedDataTag);
                xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, trace.EventId);

                trace.WriteTo(xml);

                xml.WriteEndElement();
            }

            if (exception != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExceptionTag);
                AddExceptionToTraceString(xml, exception);
                xml.WriteEndElement();
            }

            xml.WriteEndElement();
        }
        void BuildTrace(TraceEventType type, string msdnTraceCode, string description, TraceRecord trace,
            Exception exception, object source, out TraceXPathNavigator navigator)
        {
            PlainXmlWriter xmlWriter = new PlainXmlWriter(LegacyDiagnosticTrace.MaxTraceSize);
            navigator = xmlWriter.Navigator;

            this.BuildTrace(xmlWriter, type, msdnTraceCode, description, trace, exception, source);

            if (!ShouldLogPii)
            {
                navigator.RemovePii(DiagnosticStrings.HeadersPaths);
            }
        }
 private void BuildTrace(TraceEventType type, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source, out TraceXPathNavigator navigator)
 {
     PlainXmlWriter xml = new PlainXmlWriter(0xffff);
     navigator = xml.Navigator;
     this.BuildTrace(xml, type, msdnTraceCode, description, trace, exception, source);
     if (!this.TraceSource.ShouldLogPii)
     {
         navigator.RemovePii(System.ServiceModel.Diagnostics.DiagnosticStrings.HeadersPaths);
     }
 }
        static void LogInternal(MessageLogTraceRecord record)
        {
            Fx.Assert(null != record, "record cannot be null");

            PlainXmlWriter xmlWriter = new PlainXmlWriter(MessageLogger.MaxMessageSize);

            try
            {
                record.WriteTo(xmlWriter);
                xmlWriter.Close();
                TraceXPathNavigator navigator = xmlWriter.Navigator;
                
                if ((MessageLogger.messageTraceSource != null && 
                    !MessageLogger.messageTraceSource.ShouldLogPii) ||
                    !MessageLogger.LogKnownPii)
                {
                    navigator.RemovePii(MessageLogger.PiiHeadersPaths);
                    if (MessageLogger.LogMessageBody && null != record.Message)
                    {
                        if (HasSecurityAction(record.Message))
                        {
                            navigator.RemovePii(MessageLogger.PiiBodyPaths);
                        }
                    }
                }

                LogInternal(record.MessageLoggingSource, navigator);
            }
            catch (PlainXmlWriter.MaxSizeExceededException)
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.MessageNotLoggedQuotaExceeded,
                        SR.GetString(SR.TraceCodeMessageNotLoggedQuotaExceeded), record.Message);
                }
            }
        }
        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;
        }