serilog-sinks-periodicbatching icon indicating copy to clipboard operation
serilog-sinks-periodicbatching copied to clipboard

Expose a way to monitor the queue state

Open thomas-girotto opened this issue 3 years ago • 3 comments

Hello there,

I'm using the periodicbatching through elasticsearch-sink, and i'd like to be able to monitor the state of the bounded queue.

Unless i'm missing something, there's no way to know if my system is producing more logs than it can digest, and i'd find it useful to receive an alert before starting to drop LogEvents.

Something like adding in the PeriodicBatchingSinkOptions

  • a callback that would be triggered after a given threshold is reached
  • a callback that would be triggered when we're back to below this threshold
  • the threshold itself

Of course that would be useful for me only if elasticsearch-sink is ok to use those new settings, i'll ping them after your answer :)

Please let me know, i can do a PR if you're OK with the idea.

thomas-girotto avatar Sep 22 '22 07:09 thomas-girotto

Hi! Sounds good to explore, thanks!

nblumhardt avatar Sep 27 '22 08:09 nblumhardt

@nblumhardt gentle reminder: do you think you'll have time to review my PR soon ?

thomas-girotto avatar Oct 05 '22 11:10 thomas-girotto

same problem here. Using Serilog.Sinks.Splunk and spamming my logger

there's a call to _queue.TryEnqueue(logEvent) that doesn't use the boolean return value which can return false.

public bool TryEnqueue(T item)
{
    if (_queueLimit == -1)
    {
        _queue.Enqueue(item);
        return true;
    }

    bool result = true;
    try
    {
    }
    finally
    {
        if (Interlocked.Increment(ref _counter) <= _queueLimit)
        {
            _queue.Enqueue(item);
        }
        else
        {
            Interlocked.Decrement(ref _counter);
            result = false;
        }
    }

    return result;
}

vzalamea avatar Jan 06 '23 17:01 vzalamea