예제 #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());
        }
예제 #2
0
파일: Logger.cs 프로젝트: shackdan/MIMWAL
        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);
        }
예제 #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]));
        }
예제 #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);
            }
        }
예제 #5
0
 public static void FlushContextItems()
 {
     ContextItems.FlushContextItems();
 }