Is it possible to check if any errors has been logged to a `ILogger` in Serilog? -
is possible check if errors has been logged ilogger
in serilog?
var log = new loggerconfiguration().createlogger(); somealgorithm(log); // how can check if error logged?
a custom sink can this, in few lines of code.
class errordetector : ilogeventsink { volatile bool _errordetected; public bool errordetected { { return _errordetected; } } public void emit(logevent evt) { if (evt.level == logeventlevel.error || evt.level == logeventlevel.fatal) { _errordetected = true; } } }
then:
var detector = new errordetector(); var log = new loggerconfiguration() .writeto.sink(detector) .createlogger(); // later if (detector.errordetected) { ...
Comments
Post a Comment