LoggingMiddleware.cs
Код: Выделить всё
public class LoggingMiddleware : ILoggingMiddleware
{
private readonly AppsContext _context;
public LoggingMiddleware(AppsContext context)
{
_context = context;
}
public async Task LogRequestAsync(HttpContext httpContext)
{
try
{
var requestHeaders = string.Join(Environment.NewLine, httpContext.Request.Headers.Select(header => $"{header.Key} = {header.Value}"));
using var reader = new StreamReader(httpContext.Request.Body);
string requestBody = await reader.ReadToEndAsync();
var httpRequestApiLog = new HttpRequestApiLog
{
Url = httpContext.Request.GetDisplayUrl(),
RequestMethod = httpContext.Request.Method,
RequestHeaders = requestHeaders,
RequestBody = requestBody
};
_context.HttpRequestApiLogs.Add(httpRequestApiLog);
await _context.SaveChangesAsync();
}
catch (Exception)
{
throw;
}
}
}
Код: Выделить всё
private readonly ILoggingMiddleware _loggingMiddleware;
public async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
await _loggingMiddleware.LogRequestAsync(req.HttpContext);
// Other lines of code
}
Код: Выделить всё
await _context.SaveChangesAsync();
Что мне следует сделать, чтобы решить эту проблему и продолжить работу? Застрял в этой проблеме уже два дня и перепробовал все возможные ответы в Интернете.

Подробнее здесь: https://stackoverflow.com/questions/785 ... -memory-in