Ejemplo n.º 1
0
        /// <summary>
        /// Gets the extended log properties.
        /// </summary>
        /// <returns>The extended log properties string.</returns>
        private static string GetExtendedLogProperties()
        {
            StringBuilder extendedProperties = new StringBuilder();

            try
            {
                Hashtable contextItems = ContextItems.GetContextItems();
                if (contextItems != null && contextItems.Count != 0)
                {
                    extendedProperties.AppendLine();
                    extendedProperties.Append("Extended Properties:");
                    foreach (DictionaryEntry entry in contextItems)
                    {
                        string itemValue = ContextItems.GetContextItemValue(entry.Value);
                        extendedProperties.AppendLine();
                        extendedProperties.AppendFormat(CultureInfo.CurrentUICulture, "{0}: {1}", entry.Key, itemValue);
                    }
                }
            }
            catch (SecurityException)
            {
                // ignore the security exception - no item could have been set if we get the exception here.
            }
            catch (MethodAccessException)
            {
                // ignore the security exception - no item could have been set if we get the exception here.
            }

            return(extendedProperties.ToString());
        }
Ejemplo n.º 2
0
        public static string GetContextItem(object key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            Hashtable contextItems = ContextItems.GetContextItems();

            if (contextItems == null || contextItems.Count == 0 || !contextItems.ContainsKey(key))
            {
                return(null);
            }

            return(ContextItems.GetContextItemValue(contextItems[key]));
        }