コード例 #1
0
        /// <summary>
        /// Initializes the async-aware diagnostic stack, including a domain-wide hook to place the stack on all raised exceptions.
        /// </summary>
        static AsyncDiagnosticStack()
        {
            Stack = new AsyncLocalStack<string>();
            AppDomain.CurrentDomain.FirstChanceException += (_, e) =>
            {
                if (e.Exception.Data.Contains(DataKey))
                    return;

                var sb = new StringBuilder();
                foreach (var context in Current)
                    sb.AppendLine("   " + context);
                var current = sb.ToString();
                if (current != string.Empty)
                    e.Exception.Data.Add(DataKey, current);
            };
        }
コード例 #2
0
        /// <summary>
        /// Initializes the async-aware diagnostic stack, including a domain-wide hook to place the stack on all raised exceptions.
        /// </summary>
        static AsyncDiagnosticStack()
        {
            Stack = new AsyncLocalStack <string>();
            AppDomain.CurrentDomain.FirstChanceException += (_, e) =>
            {
                if (e.Exception.Data.Contains(DataKey))
                {
                    return;
                }

                var sb = new StringBuilder();
                foreach (var context in Current)
                {
                    sb.AppendLine("   " + context);
                }
                var current = sb.ToString();
                if (current != string.Empty)
                {
                    e.Exception.Data.Add(DataKey, current);
                }
            };
        }