private async ValueTask LogRequest(HttpRequest request, CancellationToken cancellationToken) { var logMessage = await _requestHandler.Handle(request, cancellationToken); var options = _options.Value; if (options.EnableConsoleLogging) { var json = JsonSerializer.Serialize(logMessage, options.JsonSerializerOptions); _requestLogger.LogInformation(json); } await _store.StoreAsync(logMessage, cancellationToken); }
public async ValueTask LogAsync(HttpContext context, CancellationToken cancellationToken = default) { var requestLog = await _requestHandler.Handle(context.Request, cancellationToken); var responseLog = await _responseHandler.Handle(context.Response, cancellationToken); var exceptionFeature = context.Features.Get <IExceptionHandlerPathFeature>(); var logContext = new LogContext(Activity.Current?.Id ?? context.TraceIdentifier, requestLog, responseLog, context.Request.Protocol, _options.HandleTimestamp()); if (exceptionFeature?.Error != null) { logContext.SetError(exceptionFeature.Error); } _logger.Log(_options.Level, default, logContext, exceptionFeature?.Error, _options.Formatter);