You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem
The application terminates before the sink has finished uploading the logs to the database.
To reproduce
Create a small console app in which you create a logger, log something, dispose the logger and exit.
Most of the time the application will terminate almost istantly and the log won't be written to the database.
Source of the bug
In the constructor of the class BatchProvider the task _batchTask, which is responsible for sending logs, is initialized using the Task.Factory.StartNew
This task should be completed only when all the logs have been written to the database, but it's not the case.
This causes the Task.WaitAll in the Dispose() method to return before all the logs have been written to the database
To make sure that _batchTask waits for all the internal tasks to finish you need to call the Unwrap() method.
This SO explains it better than i can task-factory-startnew-wont-wait-for-task-completion
The text was updated successfully, but these errors were encountered:
fbedogni
added a commit
to fbedogni/serilog-sinks-mysql
that referenced
this issue
Mar 17, 2024
Problem
The application terminates before the sink has finished uploading the logs to the database.
To reproduce
Create a small console app in which you create a logger, log something, dispose the logger and exit.
Most of the time the application will terminate almost istantly and the log won't be written to the database.
Source of the bug
In the constructor of the class BatchProvider the task _batchTask, which is responsible for sending logs, is initialized using the Task.Factory.StartNew
This task should be completed only when all the logs have been written to the database, but it's not the case.
This causes the Task.WaitAll in the Dispose() method to return before all the logs have been written to the database
To make sure that _batchTask waits for all the internal tasks to finish you need to call the Unwrap() method.
This SO explains it better than i can task-factory-startnew-wont-wait-for-task-completion
The text was updated successfully, but these errors were encountered: