/// <summary>Clears the content of current logical context.</summary> /// <param name="free">Free the full slot.</param> public static void Clear(bool free) { if (free) { MappedDiagnosticsLogicalContext.SetThreadLocal((IDictionary <string, object>)null); } else { MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(true).Clear(); } }
/// <summary> /// Gets the current logical context named item, as <see cref="T:System.Object" />. /// </summary> /// <param name="item">Item name.</param> /// <returns>The value of <paramref name="item" />, if defined; otherwise <c>null</c>.</returns> public static object GetObject(string item) { MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(false).TryGetValue(item, out var obj); return(obj); }
/// <summary> /// Removes the specified <paramref name="item" /> from current logical context. /// </summary> /// <param name="item">Item name.</param> public static void Remove(string item) { MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(true).Remove(item); }
/// <summary> /// Checks whether the specified <paramref name="item" /> exists in current logical context. /// </summary> /// <param name="item">Item name.</param> /// <returns>A boolean indicating whether the specified <paramref name="item" /> exists in current logical context.</returns> public static bool Contains(string item) { return(MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(false).ContainsKey(item)); }
/// <summary>Returns all item names</summary> /// <returns>A collection of the names of all items in current logical context.</returns> public static ICollection <string> GetNames() { return(MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(false).Keys); }
/// <summary> /// Sets the current logical context item to the specified value. /// </summary> /// <param name="item">Item name.</param> /// <param name="value">Item value.</param> public static void Set(string item, object value) { MappedDiagnosticsLogicalContext.GetLogicalThreadDictionary(true)[item] = value; }