Exemple #1
0
        private string GetValue(System.Diagnostics.Activity activity)
        {
            switch (Property)
            {
            case ActivityTraceProperty.Id: return(activity.Id);

            case ActivityTraceProperty.SpanId: return(activity.GetSpanId());

            case ActivityTraceProperty.TraceId: return(activity.GetTraceId());

            case ActivityTraceProperty.OperationName: return(activity.OperationName);

            case ActivityTraceProperty.StartTimeUtc: return(activity.StartTimeUtc > DateTime.MinValue ? activity.StartTimeUtc.ToString(Format, Culture) : string.Empty);

            case ActivityTraceProperty.Duration: return(GetDuration(activity));

            case ActivityTraceProperty.ParentId: return(activity.GetParentId());

            case ActivityTraceProperty.TraceState: return(activity.TraceStateString);

            case ActivityTraceProperty.TraceFlags: return(activity.ActivityTraceFlags == System.Diagnostics.ActivityTraceFlags.None && string.IsNullOrEmpty(Format) ? string.Empty : activity.ActivityTraceFlags.ToString(Format));

            case ActivityTraceProperty.Baggage: return(GetCollectionItem(Item, activity.Baggage));

            case ActivityTraceProperty.Tags: return(GetCollectionItem(Item, activity.TagObjects));

            case ActivityTraceProperty.CustomProperty: return(string.IsNullOrEmpty(Item) ? string.Empty : (activity.GetCustomProperty(Item)?.ToString() ?? activity.Parent?.GetCustomProperty(Item)?.ToString() ?? string.Empty));

            case ActivityTraceProperty.SourceName: return(activity.Source?.Name);

            case ActivityTraceProperty.SourceVersion: return(activity.Source?.Version);

            case ActivityTraceProperty.ActivityKind: return(ConvertToString(activity.Kind));

            default: return(string.Empty);
            }
        }
            public KeyValuePair <string, object> this[int index]
            {
                get
                {
                    int offset = index - _originalPropertyList.Count;
                    if (offset < 0)
                    {
                        return(_originalPropertyList[index]);
                    }
                    else
                    {
                        switch (offset)
                        {
                        case 0: return(new KeyValuePair <string, object>(nameof(_currentActivity.SpanId), _currentActivity.GetSpanId()));

                        case 1: return(new KeyValuePair <string, object>(nameof(_currentActivity.TraceId), _currentActivity.GetTraceId()));

                        case 2: return(new KeyValuePair <string, object>(nameof(_currentActivity.ParentId), _currentActivity.GetParentId()));
                        }
                    }

                    throw new ArgumentOutOfRangeException(nameof(index));
                }
            }