Skip to content

Enable Async Read #24

@weirdyang

Description

@weirdyang

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();
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions