-
Notifications
You must be signed in to change notification settings - Fork 29
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
Have the async sink itself write an error log event once it's buffer capacity is at, say, 10%? #77
Comments
There's no feature to directly do exactly what you asked, but the monitoring mechanism is intended to provide you the ability to do anything you desire. (I recommend reading the source of the Async Sink - its extremely small, and you'll get a clear picture of all it does and how in minimum time) |
Yeah I read the sample code, but I have no clue as to what that HealthMonitor thing is. We have no such thing in our app. |
That's it - you need to decide what to plug in - when you configure the |
I want an error log event to be inserted whenever a threshold is surpassed. The log stream generated by serilog is under scrutiny, so if any warnings related to buffer capacity would go in there it would immediately be seen. We don't have any other error reporting mechanisms beside our serilog stream. |
I get that - I was giving you suggestions for code for you to write though - you know your circumstances best. All you have to do is write the code (one reason that's not done generically is for example you would not want lots of noise from the backlog oscillating up and down around the 10% mark etc). For avoidance of doubt: there is no built in behaviour that does exactly what you are asking (and it would not make sense to add one unless a proper spec can be formulated for something which is sufficiently generic that pretty much anyone would switch it on). |
I understand your point. The trouble however of writing some external health check mechanism manually is not small though and comes with extra concerns
I'll give this some thought |
Another issue with periodic checking is that you may easily miss spikes that were resolved too quick for the monitor to notice.
What about if we provide two configuration options, |
You're right about the fact that the detection is only going to be as good as the frequency of your polling - the mechanism does not offer a push / blocking based callback mechanism. For me, that's a good thing - the possibility of a callback hanging/blocking/delaying my logging is one thing I don't want to constantly be considering. In my usage, I wrote warning messages regarding slowness writing to my Async-over-File logging to a separate healthchecks-only Console sink without buffering / Async behaviors in play - that way the diagnostic messages don't get stuck at the end of the backlog. (some might do that for SelfLog too) I'd suggest experimenting with this locally in your environment first - if you arrive at something that works well, by all means propose it after you've satisfied yourself and see if others have identical requirements. However, I think a universally applicable rule is going to be hard to define given how many different app and hosting models there are (as mentioned, some people may wish to expose the buffer usage as a metric, others may hook it into healthchecks, bt the bulk simply won't care) |
I followed more or less the same path as @chtenb and implemented some monitoring mechanisms that allow a minimum time between alerts to avoid flooding the log with warning messages. I also use the asynchronous logger in non-blocking mode and therefore accept that I may miss some messages. In the monitoring class, I have therefore delegated the task of issuing the warning to Serilog.Log.Warning() so that I can keep track of the event within other logs. This allows me to have evidence in other logs of messages lost on the asynchronous sink. However, I would prefer to be able to queue the Warning message in the underlying wrapped sinks as well, so that I can track the lost log events in the same log, but this is not possible because the wrapped sinks are not visible and the BackgroundWorkerSink class is sealed. Do you think there might be a workaround for this? |
What I did in the end is implement a file sink for the self log and have the warning messages I proposed write to that self log. |
It is a good workaround in the short term even if I find it limiting On the other hand, it should be noted that what I'm trying to do isn't always applicable and we need to distinguish between two cases where the queue fills up:
In the second case, trying to queue logs to the sink below is useless but it's still the first case. |
See my sink health monitoring and reporting implementation here. It should be generic enough for general use. |
Is it possible to have the async sink itself write an error log event once it's buffer capacity is at 10%?
The text was updated successfully, but these errors were encountered: