serilog / serilog-sinks-periodicbatching

Infrastructure for Serilog sinks that process events in batches.
Apache License 2.0
70 stars 29 forks source link

Expose a way to monitor the queue state #61

Open thomas-girotto opened 1 year ago

thomas-girotto commented 1 year ago

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

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.

nblumhardt commented 1 year ago

Hi! Sounds good to explore, thanks!

thomas-girotto commented 1 year ago

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

vzalamea commented 1 year ago

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;
}