private async Task <Response <LogsQueryResult> > ExecuteAsync(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options, bool async, CancellationToken cancellationToken = default)
        {
            if (workspaceId == null)
            {
                throw new ArgumentNullException(nameof(workspaceId));
            }

            QueryBody queryBody = CreateQueryBody(query, timeRange, options, out string prefer);

            using var message = _queryClient.CreateExecuteRequest(workspaceId, queryBody, prefer);

            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            // if (options?.Timeout != null)
            // {
            //     message.NetworkTimeout = options.Timeout;
            // }

            if (async)
            {
                await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                _pipeline.Send(message, cancellationToken);
            }

            switch (message.Response.Status)
            {
            case 200:
            {
                using var document = async ?
                                     await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false) :
                                     JsonDocument.Parse(message.Response.ContentStream, default);

                LogsQueryResult value = LogsQueryResult.DeserializeLogsQueryResult(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }

            default:
            {
                if (async)
                {
                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
                }
                else
                {
                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
                }
            }
            }
        }
        private async Task <Response <LogsQueryResult> > ExecuteAsync(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options, bool async, CancellationToken cancellationToken = default)
        {
            if (workspaceId == null)
            {
                throw new ArgumentNullException(nameof(workspaceId));
            }

            QueryBody queryBody = CreateQueryBody(query, timeRange, options, out string prefer);

            using var message = _queryClient.CreateExecuteRequest(workspaceId, queryBody, prefer);

            if (options?.ServerTimeout != null)
            {
                // Offset the service timeout a bit to make sure we have time to receive the response.
                message.NetworkTimeout = options.ServerTimeout.Value.Add(_networkTimeoutOffset);
            }

            if (async)
            {
                await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                _pipeline.Send(message, cancellationToken);
            }

            switch (message.Response.Status)
            {
            case 200:
            {
                using var document = async ?
                                     await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false) :
                                     JsonDocument.Parse(message.Response.ContentStream, default);

                LogsQueryResult value = LogsQueryResult.DeserializeLogsQueryResult(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }

            default:
            {
                if (async)
                {
                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
                }
                else
                {
                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
                }
            }
            }
        }