private static void TransferScopeDataToLogEventProperties(LogEventInfo log)
        {
            var currentScope = NestedDiagnosticsLogicalContext.PeekObject() as Scope;

            if (currentScope == null)
            {
                return;
            }

            const string scopePropertyName = "Scope";

            log.Properties.Add(scopePropertyName, currentScope.ScopeName);
            log.Properties.Add(nameof(currentScope.ScopeTrace), currentScope.ScopeTrace);
            log.Properties.Add(nameof(currentScope.ScopeId), currentScope.ScopeId.ToString());
            log.Properties.Add(nameof(currentScope.ScopeIdTrace), currentScope.ScopeIdTrace);

            foreach (var property in currentScope.Properties)
            {
                var key = property.Key;
                if (log.Properties.ContainsKey(key))
                {
                    key = "log_scope_" + key;
                }

                // to omit multiple nesting
                if (!log.Properties.ContainsKey(key))
                {
                    log.Properties.Add(key, property.Value);
                }
            }
        }
        /// <summary>
        /// Renders the specified Nested Logical Context item and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            if (TopFrames == 1)
            {
                // Allows fast rendering of topframes=1
                var topFrame = NestedDiagnosticsLogicalContext.PeekObject();
                if (topFrame != null)
                {
                    AppendAsString(topFrame, GetFormatProvider(logEvent), builder);
                }
                return;
            }

            var messages = NestedDiagnosticsLogicalContext.GetAllObjects();

            if (messages.Length == 0)
            {
                return;
            }

            int startPos = 0;
            int endPos   = messages.Length;

            if (TopFrames != -1)
            {
                endPos = Math.Min(TopFrames, messages.Length);
            }
            else if (BottomFrames != -1)
            {
                startPos = messages.Length - Math.Min(BottomFrames, messages.Length);
            }

            var    formatProvider   = GetFormatProvider(logEvent);
            string currentSeparator = string.Empty;

            for (int i = endPos - 1; i >= startPos; --i)
            {
                builder.Append(currentSeparator);
                AppendAsString(messages[i], formatProvider, builder);
                currentSeparator = Separator;
            }
        }
 private static Scope GetParentScope()
 {
     return(NestedDiagnosticsLogicalContext.PeekObject() as Scope);
 }