/// <summary> /// Gets a value associated with the given key in the current scope. /// </summary> /// <param name="key">The key to look up.</param> /// <returns>The value associated with the key, or null of the value was not set.</returns> public static object GetValue(string key) { var data = (TraceContext)AsyncLocalContext.GetData(_slot); if (data == null) { return(null); } return(data[key]); }
private static Guid GetActivityId() { // if we have stored a guid, then return that var data = AsyncLocalContext.GetData(_slot); if (data != null) { return((Guid)data); } return(Guid.Empty); }
/// <summary> /// Starts a new TraceContext scope. /// </summary> /// <returns>The new TraceContext that can be filled in.</returns> public static TraceContext Begin() { var data = (TraceContext)AsyncLocalContext.GetData(_slot); TraceContext context = null; try { context = new TraceContext(data); AsyncLocalContext.SetData(_slot, context); } catch { context.Dispose(); throw; } return(context); }