private static string FormatPath(StringBuilder builder, HttpRequest request, LoggingCollectionSettings querySettings)
        {
            return(FormatAndRollback(
                       builder,
                       b =>
            {
                b.Append(request.Method);
                b.Append(" ");
                b.Append(request.Path);

                if (querySettings.IsEnabledForRequest(request))
                {
                    if (querySettings.IsEnabledForAllKeys())
                    {
                        b.Append(request.QueryString);
                    }
                    else
                    {
                        var writtenFirst = false;

                        foreach (var pair in request.Query.Where(kvp => querySettings.IsEnabledForKey(kvp.Key)))
                        {
                            if (!writtenFirst)
                            {
                                b.Append('?');
                                writtenFirst = true;
                            }

                            b.Append($"{pair.Key}={pair.Value}");
                        }
                    }
                }
            }));
        }
        private static string FormatHeaders(StringBuilder builder, IHeaderDictionary headers, LoggingCollectionSettings settings)
        {
            return(FormatAndRollback(
                       builder,
                       b =>
            {
                foreach (var pair in headers)
                {
                    if (!settings.IsEnabledForKey(pair.Key))
                    {
                        continue;
                    }

                    b.AppendLine();
                    b.Append('\t');
                    b.Append(pair.Key);
                    b.Append(": ");
                    b.Append(pair.Value);
                }
            }));
        }