Files
speckle-sharp-connectors/Sdk/Speckle.Connectors.Logging/ActivityScopeExtensions.cs
T
Adam Hathcock 90a09fad44 Add Net8 targets for common and fix revit 2025 (#444)
* Dual target for net8.0 projects (Revit2025)

* Revit25 doesn't depend on webview anymore

* formatting
2024-12-11 12:42:37 +00:00

22 lines
686 B
C#

namespace Speckle.Connectors.Logging;
public static class ActivityScope
{
private static readonly AsyncLocal<Dictionary<string, object?>> s_tags = new() { Value = new() };
public static IReadOnlyDictionary<string, object?> Tags => s_tags.Value ?? [];
public static IReadOnlyList<KeyValuePair<string, object?>> TagsList { get; } =
new List<KeyValuePair<string, object?>>(s_tags.Value ?? []);
public static IDisposable SetTag(string key, string value)
{
s_tags.Value ??= new();
s_tags.Value[key] = value;
return new TagScope(key);
}
private sealed class TagScope(string key) : IDisposable
{
public void Dispose() => s_tags.Value?.Remove(key);
}
}