Пример #1
0
        public void Render(ILogEvent logEvent, XElement message)
        {
            var requestElement = message.Element("request");

            if (requestElement == null)
            {
                requestElement = new XElement("request");
            }
            requestElement.SetAttributeValue("id", logEvent.TryGet(KEY_REQUEST_ID, null));
            requestElement.SetAttributeValue("ip", logEvent.TryGet(KEY_REQUEST_IP, null));
            requestElement.SetAttributeValue("method", logEvent.TryGet(KEY_REQUEST_METHOD, null));
            requestElement.SetAttributeValue("url", logEvent.TryGet(KEY_REQUEST_URL, null));
            requestElement.SetAttributeValue("referrer", logEvent.TryGet(KEY_REQUEST_REFERRER, null));

            if (logEvent.IsSet(KEY_REQUEST_AGENT))
            {
                var agentElement = requestElement.Element("agent");
                if (agentElement == null)
                {
                    agentElement = new XElement("agent");
                    requestElement.Add(agentElement);
                }
                agentElement.SetValue(logEvent.Get(KEY_REQUEST_AGENT));
            }

            if (logEvent.IsSet(KEY_REQUEST_COOKIES))
            {
                var cookiesElement = requestElement.Element("cookies");
                if (cookiesElement == null)
                {
                    cookiesElement = new XElement("cookies");
                    requestElement.Add(cookiesElement);
                }
                cookiesElement.SetValue(logEvent.Get(KEY_REQUEST_COOKIES));
            }

            if (logEvent.IsSet(KEY_REQUEST_POST))
            {
                var postElement = requestElement.Element("post");
                if (postElement == null)
                {
                    postElement = new XElement("post");
                    requestElement.Add(postElement);
                }
                postElement.SetValue(logEvent.Get(KEY_REQUEST_POST));
            }

            if (requestElement.Parent == null && (!requestElement.IsEmpty || requestElement.Attributes().Any()))
            {
                message.Add(requestElement);
            }
        }
Пример #2
0
        private void PrepareEvent(ILogEvent logEvent)
        {
            if (logEvent.IsSet(EVENT_PREPARED))
                return;

            foreach (var interceptor in LogEventInterceptorProviders.Providers.GetInterceptors())
                interceptor.Prepare(logEvent);

            logEvent.Set(EVENT_PREPARED, true);
        }
Пример #3
0
        private void PrepareEvent(ILogEvent logEvent)
        {
            if (logEvent.IsSet(EVENT_PREPARED))
            {
                return;
            }

            foreach (var interceptor in LogEventInterceptorProviders.Providers.GetInterceptors())
            {
                interceptor.Prepare(logEvent);
            }

            logEvent.Set(EVENT_PREPARED, true);
        }
        public void Render(ILogEvent logEvent, XElement message)
        {
            var requestElement = message.Element("request");
            if (requestElement == null)
            {
                requestElement = new XElement("request");
            }
            requestElement.SetAttributeValue("id", logEvent.TryGet(KEY_REQUEST_ID, null));
            requestElement.SetAttributeValue("ip", logEvent.TryGet(KEY_REQUEST_IP, null));
            requestElement.SetAttributeValue("method", logEvent.TryGet(KEY_REQUEST_METHOD, null));
            requestElement.SetAttributeValue("url", logEvent.TryGet(KEY_REQUEST_URL, null));
            requestElement.SetAttributeValue("referrer", logEvent.TryGet(KEY_REQUEST_REFERRER, null));

            if (logEvent.IsSet(KEY_REQUEST_AGENT))
            {
                var agentElement = requestElement.Element("agent");
                if (agentElement == null)
                {
                    agentElement = new XElement("agent");
                    requestElement.Add(agentElement);
                }
                agentElement.SetValue(logEvent.Get(KEY_REQUEST_AGENT));
            }

            if (logEvent.IsSet(KEY_REQUEST_COOKIES))
            {
                var cookiesElement = requestElement.Element("cookies");
                if (cookiesElement == null)
                {
                    cookiesElement = new XElement("cookies");
                    requestElement.Add(cookiesElement);
                }
                cookiesElement.SetValue(logEvent.Get(KEY_REQUEST_COOKIES));
            }

            if (logEvent.IsSet(KEY_REQUEST_POST))
            {
                var postElement = requestElement.Element("post");
                if (postElement == null)
                {
                    postElement = new XElement("post");
                    requestElement.Add(postElement);
                }
                postElement.SetValue(logEvent.Get(KEY_REQUEST_POST));
            }

            if (requestElement.Parent == null && (!requestElement.IsEmpty || requestElement.Attributes().Any()))
            {
                message.Add(requestElement);
            }
        }