Skip to content

Writing logs in background jobs - Task.Factory.StartNew #4

Description

@catalingavan

Logs are persisted, by default, at the end of the HTTP Request.

If we start a background job, the log messages will not be persisted, because the HTTP Request will have already been finished by that time.

Possible quick fix is to update the LocalTextFileListener to write the logs as soon as they are provided.

KissLogApiListener (cloud listener) do needs to be instructed manually to persist the logs.

Task.Factory.StartNew(async () => {
    List<Task> tasks = new List<Task>();

    foreach (var item in mails)
    {
        Task task = _emailsService.SendEmailAsync(EmailType.ApplicationCreated, item.Model, item.To, true);
        tasks.Add(task);
    }

    await Task.WhenAll(tasks);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    SDKbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions