I have a .Net core 2.1 project that was using the Microsoft.Extensions.Logging.Internal
namespace, specifically FormattedLogValues
class.
I am now migrating to .Net core 3, I couldn't find a piece of documentation about where to FormattedLogValues
was moved or what is its replacement.
Even the namespace documentation is removed
Any tips?
I fixed the problem by updating moq
to "4.13.1" and taking advantage of It.IsAnyType
.
_logger.Verify(f => f.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<It.IsAnyType>(),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>) It.IsAny<object>()));
This really depends on what you are doing with the type, but looking at the code in the github source it looks like the type still exists, but is internal - which means tht only the library itself can actually access the type, unless you've got the assembly InternalsVisibleTo("")
- but we'll ignore that for now.
So the type itself in is an implementation of IReadOnlyList<KeyValuePair<string, object>>
which is a bit of a weird one but means that if you are testing values going into the logger you can access then like so:
logger.State[0][0].Value
"State" here is what is defined in the library so the terminology is hopefully familiar.
If you are using Moq or equivilent, you could probably use:
_logger.Verify(f => f.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<IReadOnlyList<KeyValuePair<string, object>>>(),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>) It.IsAny<object>()));
If you want to use it in your own logger you would have to create your own class that inherits from the class:
public class MyLogValues : IReadOnlyList<KeyValuePair<string, object>> {}
Then both classes can be reduced down to the interface
Hopefully this helps, I think it depends on what exactly you are using the type for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With