-
Notifications
You must be signed in to change notification settings - Fork 835
[2.2.x] Port Drop messages in azure loggers if queue is full #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ public abstract class BatchingLoggerProvider: ILoggerProvider | |
private readonly int? _batchSize; | ||
private readonly IDisposable _optionsChangeToken; | ||
|
||
private int _messagesDropped; | ||
|
||
private BlockingCollection<LogMessage> _messageQueue; | ||
private Task _outputTask; | ||
private CancellationTokenSource _cancellationTokenSource; | ||
|
@@ -78,6 +80,16 @@ private async Task ProcessLogQueue(object state) | |
limit--; | ||
} | ||
|
||
var messagesDropped = Interlocked.Exchange(ref _messagesDropped, 0); | ||
if (messagesDropped != 0) | ||
{ | ||
_currentBatch.Add(new LogMessage() | ||
{ | ||
Message = $"{messagesDropped} message(s) dropped because of queue size limit. Increase the queue size or decrease logging verbosity to avoid this.{Environment.NewLine}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about referencing BatchingLoggerOptions in this message or including a URL for the docs? |
||
Timestamp = DateTimeOffset.Now | ||
}); | ||
} | ||
|
||
if (_currentBatch.Count > 0) | ||
{ | ||
try | ||
|
@@ -91,7 +103,6 @@ private async Task ProcessLogQueue(object state) | |
|
||
_currentBatch.Clear(); | ||
} | ||
|
||
await IntervalAsync(_interval, _cancellationTokenSource.Token); | ||
} | ||
} | ||
|
@@ -107,7 +118,10 @@ internal void AddMessage(DateTimeOffset timestamp, string message) | |
{ | ||
try | ||
{ | ||
_messageQueue.Add(new LogMessage { Message = message, Timestamp = timestamp }, _cancellationTokenSource.Token); | ||
if (!_messageQueue.TryAdd(new LogMessage { Message = message, Timestamp = timestamp }, millisecondsTimeout: 0, cancellationToken: _cancellationTokenSource.Token)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not an optional parameter in this overload and I need to pass |
||
{ | ||
Interlocked.Increment(ref _messagesDropped); | ||
} | ||
} | ||
catch | ||
{ | ||
|
@@ -160,4 +174,4 @@ public ILogger CreateLogger(string categoryName) | |
return new BatchingLogger(this, categoryName); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍