/// <summary> /// Copy Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="ReadOnlyPropertiesDictionary" /> class. /// </para> /// </remarks> public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { foreach (DictionaryEntry entry in propertiesDictionary) { InnerHashtable.Add(entry.Key, entry.Value); } }
/// <summary> /// Clear the global context properties /// </summary> public void Clear() { lock (m_syncRoot) { m_readOnlyProperties = new ReadOnlyPropertiesDictionary(); } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="ReadOnlyPropertiesDictionary" /> class. /// </para> /// </remarks> public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { foreach(DictionaryEntry entry in propertiesDictionary) { InnerHashtable.Add(entry.Key, entry.Value); } }
/// <summary> /// Remove a property from the global context /// </summary> /// <param name="key">the key for the entry to remove</param> /// <remarks> /// <para> /// Removing an entry from the global context properties is relatively expensive compared /// with reading a value. /// </para> /// </remarks> public void Remove(string key) { lock (m_syncRoot) { if (m_readOnlyProperties.Contains(key)) { PropertiesDictionary propertiesDictionary = new PropertiesDictionary(m_readOnlyProperties); propertiesDictionary.Remove(key); m_readOnlyProperties = new ReadOnlyPropertiesDictionary(propertiesDictionary); } } }
/// <summary> /// Gets or sets the value of a property /// </summary> /// <value> /// The value for the property with the specified key /// </value> /// <remarks> /// <para> /// Reading the value for a key is faster than setting the value. /// When the value is written a new read only copy of /// the properties is created. /// </para> /// </remarks> public override object this[string key] { get { return(m_readOnlyProperties[key]); } set { lock (m_syncRoot) { var mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps[key] = value; m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }
/// <summary> /// Remove a property from the global context /// </summary> /// <param name="key">the key for the entry to remove</param> /// <remarks> /// <para> /// Removing an entry from the global context properties is relatively expensive compared /// with reading a value. /// </para> /// </remarks> public void Remove(string key) { lock (m_syncRoot) { if (m_readOnlyProperties.Contains(key)) { var mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps.Remove(key); m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }
private IList <string> ExtractTags(ReadOnlyPropertiesDictionary loggingEventProperties) { var rawTags = ResolveTagsFromLog4NetProperties(loggingEventProperties); if (!string.IsNullOrEmpty(rawTags)) { LogLog.Debug(DeclaringType, string.Format("RaygunAppender: Found '{0}' property key, extracting raygun tags from '{1}'", RaygunAppenderBase.PropertyKeys.Tags, rawTags)); return(rawTags.Split('|').ToList()); } return(null); }
/// <summary> /// Gets or sets the value of a property /// </summary> /// <value> /// The value for the property with the specified key /// </value> /// <remarks> /// <para> /// Reading the value for a key is faster than setting the value. /// When the value is written a new read only copy of /// the properties is created. /// </para> /// </remarks> public override object this[string key] { get { return(m_readOnlyProperties[key]); } set { lock (m_syncRoot) { PropertiesDictionary propertiesDictionary = new PropertiesDictionary(m_readOnlyProperties); propertiesDictionary[key] = value; m_readOnlyProperties = new ReadOnlyPropertiesDictionary(propertiesDictionary); } } }
/// <summary> /// Flatten this composite collection into a single properties dictionary /// </summary> /// <returns>the flattened dictionary</returns> /// <remarks> /// <para> /// Reduces the collection of ordered dictionaries to a single dictionary /// containing the resultant values for the keys. /// </para> /// </remarks> public PropertiesDictionary Flatten() { if (m_flattened == null) { m_flattened = new PropertiesDictionary(); for (int i = m_nestedProperties.Count; --i >= 0;) { ReadOnlyPropertiesDictionary cur = (ReadOnlyPropertiesDictionary)m_nestedProperties[i]; foreach (DictionaryEntry entry in cur) { m_flattened[(string)entry.Key] = entry.Value; } } } return(m_flattened); }
/// <summary> /// Add a Properties Dictionary to this composite collection /// </summary> /// <param name="properties">the properties to add</param> /// <remarks> /// <para> /// Properties dictionaries added first take precedence over dictionaries added /// later. /// </para> /// </remarks> public void Add(ReadOnlyPropertiesDictionary properties) { m_flattened = null; m_nestedProperties.Add(properties); }
private RaygunIdentifierMessage ExtractAffectedUser(ReadOnlyPropertiesDictionary loggingEventProperties) { return((loggingEventProperties[RaygunAppenderBase.PropertyKeys.AffectedUser] ?? ThreadContext.Properties[RaygunAppenderBase.PropertyKeys.AffectedUser] ?? GlobalContext.Properties[RaygunAppenderBase.PropertyKeys.AffectedUser]) as RaygunIdentifierMessage); }
/// <summary> /// Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="PropertiesDictionary" /> class. /// </para> /// </remarks> public PropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) : base(propertiesDictionary) { }
private string ResolveTagsFromLog4NetProperties(ReadOnlyPropertiesDictionary loggingEventProperties) { return((loggingEventProperties[RaygunAppenderBase.PropertyKeys.Tags] ?? ThreadContext.Properties[RaygunAppenderBase.PropertyKeys.Tags] ?? GlobalContext.Properties[RaygunAppenderBase.PropertyKeys.Tags]) as string); }
private T ResolveFromLog4NetProperties <T>(ReadOnlyPropertiesDictionary loggingEventProperties, string key) where T : class { return(loggingEventProperties[key] as T); }
private HttpRequestMessage ResolveHttpRequestMessageFromLog4NetProperties(ReadOnlyPropertiesDictionary loggingEventProperties) { return(ResolveFromLog4NetProperties <HttpRequestMessage>(loggingEventProperties, PropertyKeys.HttpRequestMessage)); }
private T ResolveFromLog4NetProperties <T>(ReadOnlyPropertiesDictionary loggingEventProperties, string key) where T : class { return((loggingEventProperties[key] ?? LogicalThreadContext.Properties[key] ?? ThreadContext.Properties[key] ?? GlobalContext.Properties[key]) as T); }
private RaygunIdentifierMessage ExtractAffectedUser(ReadOnlyPropertiesDictionary loggingEventProperties) { return(ResolveFromLog4NetProperties <RaygunIdentifierMessage>(loggingEventProperties, RaygunAppenderBase.PropertyKeys.AffectedUser)); }
static IEnumerable <KeyValuePair <string, string> > AsPairs(this ReadOnlyPropertiesDictionary self) { return(self.GetKeys().Select(key => Pair.For(key, self[key].ToStringOrNull()))); }
private string ResolveTagsFromLog4NetProperties(ReadOnlyPropertiesDictionary loggingEventProperties) { return(loggingEventProperties[RaygunAppenderBase.PropertyKeys.Tags] as string); }