serilog-contrib / SerilogSinksInMemory

In-memory sink for Serilog to use for testing
MIT License
53 stars 7 forks source link

Add InMemorySink.Clear() #19

Closed sungam3r closed 3 years ago

sungam3r commented 3 years ago

When testing, it can be convenient to clear messages.

sandermvanvliet commented 3 years ago

Hi @sungam3r,

it can definitely be handy to clear log messages when you are testing. Currently this is possible through the Dispose method on the sink: https://github.com/sandermvanvliet/SerilogSinksInMemory#clearing-log-events-between-tests

The main reason that the sink does not have a Clear method is to encourage the right usage of the sink which is to have only one instance of it per test so that clearing it wouldn't be necessary. Unfortunately we've seen that with MS Test this doesn't always work and that's why the Dispose pattern was introduced to solve that particular problem.

However, I can't claim to know all use cases so I'm curious to how you would use this. Do you have an example of a test where you would use Clear?

sungam3r commented 3 years ago

OK. I just did not notice Dispose method, it happens.

sandermvanvliet commented 3 years ago

No worries!