Esempio n. 1
0
        public WebContextProxy GetContextOfRequest()
        {
            OperationContext context = OperationContext.Current;
            if (context == null) return null ;

            WebContextProxy wc = new WebContextProxy();

            MessageProperties messageProperties = context.IncomingMessageProperties;
            if (messageProperties != null)
            {
                if (messageProperties.Via != null)
                {
                    wc.parameters = messageProperties.Via.Query;
                    wc.method = messageProperties.Via.LocalPath;
                }
            }

            WebOperationContext webContext = WebOperationContext.Current;
            if ((webContext != null) && (webContext.IncomingRequest != null)
                && (webContext.IncomingRequest.Headers["X-Forwarded-For"] != null)) //forwarded IP through load balancer
                wc.ip = webContext.IncomingRequest.Headers["X-Forwarded-For"];
            else if (messageProperties != null)
            {
                RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name]
                        as RemoteEndpointMessageProperty;
                if (endpointProperty != null)
                    wc.ip = endpointProperty.Address;
            }
            return wc;
        }
Esempio n. 2
0
        public void LogTransaction(string clientAlias, string result, string duration, WebContextProxy context = null)
        {
            string ip = "";
            string method = "";
            string parameters = "";
            try
            {
            #if WEB
                WebHelper wh = new WebHelper();
                wh.GetContextOfRequest(out ip, out method, out parameters);
            #endif
                if (context != null)
                {
                    ip = context.ip;
                    method = context.method;
                    parameters = context.parameters;
                }
                LogTransaction(clientAlias, ip, method, parameters, result, duration);

                if (m_initCalled) //log the call that forced instantiation
                {
                    string message = "Call that forced instantiation:"
                                                + "\nip = " + ip
                                                + "\nmethod = " + method
                                                + "\nparameters = " + parameters;
                    BoostLog.Instance.WriteEntry(message, EventLogEntryType.Information, clientAlias);
                    m_initCalled = false;
                }
            }
            catch (Exception ex)
            {
                BoostLog log = BoostLog.Instance;
                if (log != null)
                {
                    log.Suffix = "ip = " + ip
                                        + "\nmethod = " + method
                                        + "\nparameters = " + parameters
                                        + "\nresult = " + result;
                    string errMsg = "Error logging transaction: " + ex.Message;
                    if (ex.InnerException != null)
                        errMsg += "\nInnerException: " + ex.InnerException.Message;
                    log.WriteEntry(errMsg, EventLogEntryType.Warning, clientAlias);
                }
            }
        }