/// <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> /// Sets the current logical context item to the specified value. /// </summary> /// <param name="item">Item name.</param> /// <param name="value">Item value.</param> /// <returns>>An <see cref="T:System.IDisposable" /> that can be used to remove the item from the current logical context.</returns> public static IDisposable SetScoped(string item, object value) { MappedDiagnosticsLogicalContext.Set(item, value); return((IDisposable) new MappedDiagnosticsLogicalContext.ItemRemover(item)); }
/// <summary> /// Gets the current logical context named item, as <see cref="T:System.String" />. /// </summary> /// <param name="item">Item name.</param> /// <returns>The value of <paramref name="item" />, if defined; otherwise <see cref="F:System.String.Empty" />.</returns> /// <remarks>If the value isn't a <see cref="T:System.String" /> already, this call locks the <see cref="T:NLog.LogFactory" /> for reading the <see cref="P:NLog.Config.LoggingConfiguration.DefaultCultureInfo" /> needed for converting to <see cref="T:System.String" />. </remarks> public static object Get(string item) { return(MappedDiagnosticsLogicalContext.Get(item, (IFormatProvider)null)); }
/// <summary> /// Gets the current logical context named item, as <see cref="T:System.String" />. /// </summary> /// <param name="item">Item name.</param> /// <param name="formatProvider">The <see cref="T:System.IFormatProvider" /> to use when converting a value to a string.</param> /// <returns>The value of <paramref name="item" />, if defined; otherwise <see cref="F:System.String.Empty" />.</returns> /// <remarks>If <paramref name="formatProvider" /> is <c>null</c> and the value isn't a <see cref="T:System.String" /> already, this call locks the <see cref="T:NLog.LogFactory" /> for reading the <see cref="P:NLog.Config.LoggingConfiguration.DefaultCultureInfo" /> needed for converting to <see cref="T:System.String" />. </remarks> public static object Get(string item, IFormatProvider formatProvider) { return(FormatHelper.Convert(MappedDiagnosticsLogicalContext.GetObject(item), formatProvider)); }
/// <summary>Clears the content of current logical context.</summary> public static void Clear() { MappedDiagnosticsLogicalContext.Clear(false); }
/// <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; }