Пример #1
0
        /// <summary>
        /// Gets the extended log properties.
        /// </summary>
        /// <returns>The extended log properties string.</returns>
        private static string GetExtendedLogProperties()
        {
            var extendedProperties = new StringBuilder();

            try
            {
                var contextItems = LoggerCallContextItems.GetContextItems();
                if (contextItems != null && contextItems.Count != 0)
                {
                    foreach (DictionaryEntry entry in contextItems)
                    {
                        var itemValue = LoggerCallContextItems.GetContextItemValue(entry.Value);
                        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
        public static string GetContextItem(object key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var contextItems = LoggerCallContextItems.GetContextItems();

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

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