datalust / serilog-sinks-seq

A Serilog sink that writes events to the Seq structured log server
https://datalust.co/seq
Apache License 2.0
225 stars 50 forks source link

Log entries to seq appear blocked when using serilog-sinks-seq #155

Closed chrisbint closed 2 years ago

chrisbint commented 2 years ago

I have some unusual behaviour and I am trying to figure out whether it is our code or serilog-sinks-seq.

We have a fairly simple net 5 console app that uses async methods to do what it needs to do. The behaviour I am seeing is that the log entries are not appearing in seq until 'after' we await and complete an async method.

For example, with the following 5 lines of code;

  1. _ logger.LogInformation($"Processing user {user}",user.Email);
  2. _logger.LogError($"Processing user {user}", user.Email)
  3. var domains = await _domainRepository.ListAsync(new ActiveDomainsForUser(user.Id, true));
  4. foreach (var domain in domains)

If I put a breakpoint on line 3, the seq logs do not arrive. If I then step through to line 4, the seq logs then arrive.

I can sit on the breakpoint and not continue for as long as I want, the moment line 3 has completed, the logs arrive in seq.

Line 3 calls a generic repository which itself has no instance of ILogger injected.

As a test, if I add another call to an async service and call this, the same behaviour exists. In fact this adds another dimension to the problem;

  1. _logger.LogInformation($"Processing user {user}",user.Email);
  2. _logger.LogError($"Processing user {user}", user.Email);
  3. var request = new EmailRequest("chris@xxxxx", "Processing Notifications", "", "support@xxxx", true);
  4. await _emailService.SendAsync(request);
  5. var domains = await _domainRepository.ListAsync(new ActiveDomainsForUser(user.Id, true));

If I put a breakpoint on line 3, the seq logs do not arrive. If I then step through to line 4, the seq logs do not arrive. If I then step through to line 5, the seq logs DO arrive. However, step 4 also has an ILogger instance with a call to ILogger.LogInformation and this does not come through until I continue from line 5.

So, for each scenario, the seq logs are only delivered after one my async methods are awaited and completed and only then, logs that were created prior to the call to that async method, any seq logs created within the async method are not delivered until the next async method is completed.

Any suggestions would be welcome!

nblumhardt commented 2 years ago

Answered via: https://docs.datalust.co/v2021.1/discuss/6170929e3bb8900077be66e3