コード例 #1
0
        /// <summary>
        /// Performs the SOAP and HTTP logging.
        /// </summary>
        /// <param name="service">The SOAP service.</param>
        /// <param name="soapResponse">The SOAP response xml.</param>
        /// <param name="soapRequest">The SOAP request xml.</param>
        private void PerformLogging(AdsClient service, string soapRequest, string soapResponse)
        {
            if (service == null || service.User == null || soapRequest == null || soapResponse == null)
            {
                return;
            }

            if (config.MaskCredentials)
            {
                XmlDocument xDoc = SerializationUtilities.LoadXml(soapRequest);
                MaskCredentialsInLogs(xDoc, GetFieldsToMask());
                soapRequest = xDoc.OuterXml;
            }

            string formattedSoapRequest  = FormatSoapRequest(service.LastRequest, soapRequest);
            string formattedSoapResponse = FormatSoapResponse(service.LastResponse, soapResponse);
            string formattedHttpRequest  = FormatHttpRequest(soapRequest);
            string formattedHttpResponse = FormatHttpResponse(soapResponse);

            string soapLog    = formattedSoapRequest + formattedSoapResponse;
            string requestLog = string.Format(CultureInfo.InvariantCulture, "host={0},url={1},{2},{3}",
                                              service.LastRequest.RequestUri.Host, service.LastRequest.RequestUri.AbsolutePath,
                                              formattedHttpRequest, formattedHttpResponse);

            ContextStore.AddKey("FormattedSoapLog", soapLog);
            ContextStore.AddKey("FormattedRequestLog", requestLog);

            bool isError = service.LastResponse != null && service.LastResponse is HttpWebResponse &&
                           (service.LastResponse as HttpWebResponse).StatusCode ==
                           HttpStatusCode.InternalServerError;

            TraceUtilities.WriteSoapXmlLogs(soapLog, isError);
            TraceUtilities.WriteRequestInfoLogs(requestLog, isError);
        }