Example #1
0
        internal void ContinueCatTransaction()
        {
            string identity = EndpointHost.Config.MetadataMap[ServicePath].OperationNameMap[OperationName].Key;

            if (_httpRequest.IsH5GatewayRequest())
            {
                return;
            }

            string clientAppId = _httpRequest.GetClientAppId();

            if (string.IsNullOrWhiteSpace(clientAppId))
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(ServiceUtils.AppId))
            {
                _context.Response.AddHeader(ServiceUtils.ServiceAppIdHttpHeaderKey, ServiceUtils.AppId);
                _context.Response.AddHeader(ServiceUtils.ESBServiceAppIdHttpHeaderKey, ServiceUtils.AppId);
            }

            _context.Response.AddHeader(ServiceUtils.ServiceHostIPHttpHeaderKey, ServiceUtils.HostIP);
            _context.Response.AddHeader(ServiceUtils.ESBServiceHostIPHttpHeaderKey, ServiceUtils.HostIP);
        }
Example #2
0
        internal static void LogError(string title, IHttpRequest httpRequest, ResponseStatusType responseStatus, string errorCode, LogLevel logLevel)
        {
            if (httpRequest == null)
            {
                return;
            }

            ServiceMetadata             metadata = EndpointHost.Config.MetadataMap[httpRequest.ServicePath];
            Dictionary <string, string> additionalExceptionInfo = new Dictionary <string, string>()
            {
                { "Version", ServiceUtils.SOA2VersionCatName },
                { "Operation", metadata.FullServiceName + "." + httpRequest.OperationName }
            };

            string clientAppId = httpRequest.GetClientAppId();

            if (!string.IsNullOrWhiteSpace(clientAppId))
            {
                additionalExceptionInfo.Add("ClientAppId", clientAppId);
            }

            if (!string.IsNullOrWhiteSpace(errorCode))
            {
                additionalExceptionInfo.Add("ErrorCode", errorCode);
            }

            if (metadata.LogErrorWithRequestInfo)
            {
                try
                {
                    try
                    {
                        var requestInfo = RequestInfoHandler.GetRequestInfo(httpRequest);
                        additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo);
                    }
                    catch
                    {
                        Dictionary <string, string> requestInfo = new Dictionary <string, string>()
                        {
                            { "Url", httpRequest.RawUrl },
                            { "PathInfo", httpRequest.PathInfo },
                            { "QueryString", TypeSerializer.SerializeToString(httpRequest.QueryString) },
                            { "Headers", TypeSerializer.SerializeToString(httpRequest.Headers) },
                            { "FormData", TypeSerializer.SerializeToString(httpRequest.FormData) }
                        };
                        additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo);
                    }
                }
                catch
                {
                }

                if (httpRequest.RequestObject != null && !(httpRequest.RequestObject is RequestInfoResponse))
                {
                    additionalExceptionInfo["RequestObject"] = TypeSerializer.SerializeToString(httpRequest.RequestObject);
                }
            }

            string message = string.Empty;

            if (responseStatus != null)
            {
                additionalExceptionInfo["ResponseStatus"] = TypeSerializer.SerializeToString(responseStatus);
                if (responseStatus.Errors != null && responseStatus.Errors.Count > 0 && responseStatus.Errors[0] != null)
                {
                    message = string.Format("ErrorCode: {0}, Message: {1}", responseStatus.Errors[0].ErrorCode, responseStatus.Errors[0].Message);
                }
            }

            switch (logLevel)
            {
            case LogLevel.DEBUG:
                Log.Debug(title, message, additionalExceptionInfo);
                break;

            case LogLevel.INFO:
                Log.Info(title, message, additionalExceptionInfo);
                break;

            case LogLevel.WARN:
                Log.Warn(title, message, additionalExceptionInfo);
                break;

            case LogLevel.ERROR:
                Log.Error(title, message, additionalExceptionInfo);
                break;

            case LogLevel.FATAL:
                Log.Fatal(title, message, additionalExceptionInfo);
                break;
            }
        }
Example #3
0
        internal static void LogError(string title, IHttpRequest httpRequest, Exception ex, string errorCode, LogLevel logLevel)
        {
            if (httpRequest == null)
            {
                return;
            }

            ServiceMetadata             metadata = EndpointHost.Config.MetadataMap[httpRequest.ServicePath];
            Dictionary <string, string> additionalExceptionInfo = new Dictionary <string, string>()
            {
                { "Operation", metadata.FullServiceName + "." + httpRequest.OperationName }
            };

            string clientAppId = httpRequest.GetClientAppId();

            if (!string.IsNullOrWhiteSpace(clientAppId))
            {
                additionalExceptionInfo.Add("ClientAppId", clientAppId);
            }

            if (!string.IsNullOrWhiteSpace(errorCode))
            {
                additionalExceptionInfo.Add("ErrorCode", errorCode);
            }

            if (metadata.LogErrorWithRequestInfo)
            {
                try
                {
                    try
                    {
                        var requestInfo = RequestInfoHandler.GetRequestInfo(httpRequest);
                        additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo);
                    }
                    catch
                    {
                        Dictionary <string, string> requestInfo = new Dictionary <string, string>()
                        {
                            { "Url", httpRequest.RawUrl },
                            { "PathInfo", httpRequest.PathInfo },
                            { "QueryString", TypeSerializer.SerializeToString(httpRequest.QueryString) },
                            { "Headers", TypeSerializer.SerializeToString(httpRequest.Headers) },
                            { "FormData", TypeSerializer.SerializeToString(httpRequest.FormData) }
                        };
                        additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo);
                    }
                }
                catch
                {
                }

                if (httpRequest.RequestObject != null && !(httpRequest.RequestObject is RequestInfoResponse))
                {
                    additionalExceptionInfo["RequestObject"] = TypeSerializer.SerializeToString(httpRequest.RequestObject);
                }
            }

            switch (logLevel)
            {
            case LogLevel.DEBUG:
                if (ex != null)
                {
                    Log.Error(title, ex, additionalExceptionInfo);
                }
                else
                {
                    Log.Error(title, string.Empty, additionalExceptionInfo);
                }
                break;

            case LogLevel.INFO:
                if (ex != null)
                {
                    Log.Info(title, ex, additionalExceptionInfo);
                }
                else
                {
                    Log.Info(title, string.Empty, additionalExceptionInfo);
                }
                break;

            case LogLevel.WARN:
                if (ex != null)
                {
                    Log.Warn(title, ex, additionalExceptionInfo);
                }
                else
                {
                    Log.Warn(title, string.Empty, additionalExceptionInfo);
                }
                break;

            case LogLevel.ERROR:
                if (ex != null)
                {
                    Log.Error(title, ex, additionalExceptionInfo);
                }
                else
                {
                    Log.Error(title, string.Empty, additionalExceptionInfo);
                }
                break;

            case LogLevel.FATAL:
                if (ex != null)
                {
                    Log.Fatal(title, ex, additionalExceptionInfo);
                }
                else
                {
                    Log.Fatal(title, string.Empty, additionalExceptionInfo);
                }
                break;
            }
        }