Exemplo 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());
        }
Exemplo n.º 2
0
        public static void SetContextItem(object key, object value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            ContextItems.SetContextItem(key, value);
        }
Exemplo n.º 3
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]));
        }
Exemplo n.º 4
0
        public static void SetContextItem(object key, object value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (value is string && !string.IsNullOrEmpty(value as string))
            {
                // remove any curly braces as they cause FormatException in WriteEvent method when args is passed to it.
                var stringValue = ((string)value).Replace("{", string.Empty).Replace("}", string.Empty);
                ContextItems.SetContextItem(key, stringValue);
            }
            else
            {
                ContextItems.SetContextItem(key, value);
            }
        }
Exemplo n.º 5
0
 public static void FlushContextItems()
 {
     ContextItems.FlushContextItems();
 }