Exemplo n.º 1
0
        /// <summary>
        /// Enumerate the keys stored in the context and
        /// serialize them to an XML blob
        /// </summary>
        private static string SerializeToXML(IEnumerable <string> keyCollection)
        {
            var sb = new StringBuilder();

            using (var tw = new StringWriter(sb))
                using (var xw = new XmlTextWriter(tw))
                {
                    xw.WriteStartElement("loggingContext");
                    foreach (var key in keyCollection)
                    {
                        var    frameData = new LoggingCallContextActiveFrameData(key);
                        object data;
                        xw.WriteStartElement(key);
                        if (frameData.TryGetValue(out data) && data != null)
                        {
                            xw.WriteString(data.ToString());
                        }
                        else
                        {
                            xw.WriteString("(Unknown)");
                        }
                        xw.WriteEndElement();
                    }
                    xw.WriteEndElement();
                }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves the current active value for the key
        /// </summary>
        public static bool TryGetContextData(string key, out object result)
        {
            LoggingCallContextActiveFrameData data = new LoggingCallContextActiveFrameData(key);

            return(data.TryGetValue(out result));
        }