/// <summary> /// Adds multiple properties to the logical context and returns an <see cref="IDisposable"/> that can be used to remove them all when they no longer applies to the stack. /// </summary> /// <param name="properties">An array of <see cref="KeyValuePair{TKey, TValue}"/> instances describing the properties to add.</param> /// <returns>An <see cref="IDisposable"/> that can be used to remove the property (by calling <see cref="IDisposable.Dispose"/>.</returns> /// <remarks> /// <para>Note that if the property value is not serialisable, errors may occur when making calls across app domain/remoting boundaries etc. Ideally only primitive types should be used for call context properties.</para> /// </remarks> public static IDisposable PushProperties(params KeyValuePair <string, object>[] properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } if (!Utils.Any(properties)) { throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeEmpty, nameof(properties)), nameof(properties)); } LogCallContextProperty retVal = null; foreach (var property in properties) { CurrentContext = CurrentContext.Push(new KeyValuePair <string, object>(property.Key, property.Value)); if (retVal == null) { retVal = new LogCallContextProperty(); } else { retVal = new LogCallContextProperty(retVal); } } return(retVal); }
public LogCallContextProperty(LogCallContextProperty childProperty) { _ChildProperty = childProperty; }