-
-
Notifications
You must be signed in to change notification settings - Fork 96
Description
I noticed that our log messages sent through an ILogger connected to Serilog are not displayed in the Standard Output for tests. I'm trying to determine if this is a misunderstanding on my part, or maybe some kind of conflict between Serilog's console outputter and TUnit's console interceptor? While I understand this may not be a direct issue with TUnit, Im reaching out via this repository/issue to see if others have experienced similar situations and have found any working solutions.
I also noticed that the static Serilog logger configured and message logged on line L3-4 are visible in the test output, maybe something to do with log messages and test correlation?
Repository with minimal example code can be found here.
- The example code is created by using the
TUnit ASP.NET Core Projecttemplate. - Then I followed the Serilog instructions.
- Finally I injected the
ILoggerinto the ping endpoints anonymous function, and added a log message.
I also tested the traditional controller based API setup with the same results.
How to trigger
In the code, you can toggle between only the default Microsoft ILogger and ILogger connected with Serilog by commenting out AddSerilog() on L13.
When running the application and calling the endpoint, both Serilog and the default ILogger logs the message as expected to the console. I can see the log message with both setups.
But when calling the same endpoint from the Test() with Serilog enabled, the message is not part of the test output.
Expected behavior: Logging to Console with Serilog should also show messages in the test standard output.
Running Test With Serilog enabled - Not as expected

Running Test without Serilog - As expected

Running application with Serilog enabled - As expected

Running application without Serilog - As expected

Side note: I suspect a custom Serilog Sink that uses the TUnit TestContext could solve this. But since Serilog is so popular and I couldnt find anyone else running into this, I figured Id ask here first. Is there maybe a more straightforward solution I'm missing?