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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -