Closed ahahn95 closed 4 years ago
How many log events are you emitting? This sink keeps all log events written to the TestCorrelator in memory so that it can give them back to you for asserts. If you're logging a ton of events, or those events have large property payloads, you will run out of memory.
Your extension method adds property payload, so I'd assume that is why you run out of memory.
I'm only logging that one message once. When you say property payload, do you mean the propertyValues arguments that I have? Also, I would think that the TestCorrelator would not be running anymore, since this test has already passed, but as you can see, it's causing unit tests that come like 10 tests later to fail.
Yep that's what I mean.
You're setting the global static logger to use the TestCorrelator. That means everything that uses that logger will write there. Log.Logger is a global static resource. If you're really just interested in testing the extension method, create a new logger, but don't assign it to Log.Logger.
There is a performance improvement to be made here that I've been putting off for a while just because testing it is a bit difficult. The change would be that log events that aren't emitted within a context are not stored. I'll create an issue to track that enhancement.
Great, thank you a ton for the quick responses!
When I use extension methods for
ILogger
, I get the below error message (but not on my serilog tests, it's usually during other tests in my pipeline, which is confusing to me because I would think that tests are self enclosed).Is this a bug or am I implementing my extension methods incorrectly?
Also, everything seems to work fine without the extension methods.
The error message is
My test method is
My extension method looks like