/// <summary> /// Add Distributed Context entry to the builder. /// </summary> /// <param name="entry">Entry to add to the context.</param> /// <returns>The current <see cref="CorrelationContextBuilder"/> instance.</returns> public CorrelationContextBuilder Add(CorrelationContextEntry entry) { if (DistributedContext.Carrier is NoopDistributedContextCarrier || entry == default) { return(this); } if (this.entries == null) { this.entries = new List <CorrelationContextEntry>(); } else { for (int i = 0; i < this.entries.Count; i++) { if (this.entries[i].Key == entry.Key) { this.entries[i] = entry; return(this); } } } this.entries.Add(entry); return(this); }
/// <summary> /// Create <see cref="CorrelationContext"/> instance from entry. /// </summary> /// <param name="entry">Entry to add to the context.</param> /// <returns>Instance of <see cref="CorrelationContext"/>.</returns> public static CorrelationContext CreateContext(CorrelationContextEntry entry) => new CorrelationContextBuilder(inheritCurrentContext: false).Add(entry).Build();