We needed to add logging support to our library Platron.Client - API client to payment service https://platron.ru.
What we decided not do: invent a new logger. Therefore there is not so much opportunities. Adding one more constraint - don’t add nuget dependency - and there is LibLog appears. As for me - it’s code due of supporting several platforms and adding compile time options is not readable and easily supportable. But it can be seamlessly integrated with several popular loggers, and one more thing to mention - it was used in IdentityServer.
First of install package LibLog. It will place single file in App_Packages\LibLog.4.2\LibLog.cs.
One nice thing is namespace - it was just what doctor ordered:
In our case we needed to log only couple of things: request, response, exception details. So all integration took several minutes.
Most interesting thing here is how to test it. Test correctness of logged information and make sure that it will really help to find out reasons of errors using library.
We already have a bunch of integrational tests on XUnit. To see results of our fresh logger we need to integrate LibLog with ITestOutputHelper which provides method to write to test result log.
Actually it was trickier then I thought, without sample it would be painfull.
And one last step:
Let’s run couple of tests and see expected profit :).
All sources have been published as a part of Platron.Client. Feel free to use it in your projects :).