serilog-formatting-compact-reader
serilog-formatting-compact-reader copied to clipboard
Enable Async Read
Hi, I'm trying to use this in a web api, however, the tryRead is a synchronous action and is causing the application to throw an exception.
Do you recommend enabling Server.AllowSynchronousIO = true?
This is my current workaround:
[HttpPost("api/log-events")]
public async Task<IActionResult> Post()
{
Serilog.Events.LogEvent evt;
var apiKey = Request.Headers["X-HEIMDALL-KEY"].FirstOrDefault();
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var log = new LogEventReader(reader);
string line;
while (!string.IsNullOrWhiteSpace(line = await reader.ReadLineAsync()))
{
evt = LogEventReader.ReadFromString(line);
Log.Logger.Information(evt.RenderMessage());
_publisher.Publish<LogEvent>("test", evt);
}
};
return Ok();
}
Hi! For now I think allowing synchronous IO will be the quickest way to go, but support for async reads in this library would be a great addition. Marked as up-for-grabs
in case anyone following along is interested in exploring/implementing this. Thanks!
I'd like to create a new PR for this ticket.
@Blaisor please go ahead 👍