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
Describe the bug
A race condition within the BatchProvider Dispose method prevents final logs from being written in some cases. Sometimes the log messages are written successfully, and other times they are not. When they are not written successfully, a SelfLog message is written with the InvalidOperationException message: "The collection argument is empty and has been marked as complete with regards to additions." This message is indicative of the scenario where .Take() is called on a BlockingCollection that is already completed and empty.
To Reproduce
Create a .NET background service that logs to a default AzureAnalytics sink. Enable SelfLog logging. Example Program.cs
Start and stop the process and review the SelfLog to identify when the issue occurs. The exception is thrown from this line:
I've been able to reproduce more frequently when running the application within an Linux Docker container than I have when running on my Windows desktop in Visual Studio.
Expected behavior
During logger disposal, all pending log messages should be written to the Azure Log Analytics Workspace. None should be missed.
2022-11-14 12:27:34 2022-11-14T17:27:34.4925474Z Sending batch of 4 logs
2022-11-14 12:27:35 2022-11-14T17:27:35.3973612Z Transferring log: [OK]
2022-11-14 12:27:46 2022-11-14T17:27:46.4924008Z Halting sink...
2022-11-14 12:27:46 2022-11-14T17:27:46.4935898Z The collection argument is empty and has been marked as complete with regards to additions.
2022-11-14 12:27:46 2022-11-14T17:27:46.4936554Z Sink halted successfully.
The text was updated successfully, but these errors were encountered:
Describe the bug
A race condition within the BatchProvider Dispose method prevents final logs from being written in some cases. Sometimes the log messages are written successfully, and other times they are not. When they are not written successfully, a SelfLog message is written with the InvalidOperationException message: "The collection argument is empty and has been marked as complete with regards to additions." This message is indicative of the scenario where .Take() is called on a BlockingCollection that is already completed and empty.
To Reproduce
Create a .NET background service that logs to a default AzureAnalytics sink. Enable SelfLog logging.
Example Program.cs
Start and stop the process and review the SelfLog to identify when the issue occurs. The exception is thrown from this line:
serilog-sinks-azure-analytics/src/Serilog.Sinks.AzureAnalytics/Sinks/Batch/BatchProvider.cs
Line 211 in d71b5ef
and caught/logged at this line:
serilog-sinks-azure-analytics/src/Serilog.Sinks.AzureAnalytics/Sinks/Batch/BatchProvider.cs
Line 219 in d71b5ef
I've been able to reproduce more frequently when running the application within an Linux Docker container than I have when running on my Windows desktop in Visual Studio.
Expected behavior
During logger disposal, all pending log messages should be written to the Azure Log Analytics Workspace. None should be missed.
Screenshots
SelfLog under successful scenario:
SelfLog under unsuccessful scenario:
The text was updated successfully, but these errors were encountered: