This project contains a demo app for the How to test logging when using Microsoft.Extensions.Logging guide.
This app is an ASP.NET web api and a test project that shows how to use MELT and Serilog to test logging in integration tests.
- Open the
TestingLogsWithSerilog.sln
which can be found atsrc/guides/serilog/TestingLogsWithSerilog
. - Run the tests. Both tests should pass.
SerilogConfigurationExtensions.cs
shows an example setup of the Serilog logger. This is used on theProgram.cs
as part of building theIHostBuilder
.- The
DemoTests1.cs
test shows how to do test your logging in integration tests when using Serilog as your logging framework. TheDemoTests2.cs
test is the same asDemoTest1
but it uses a customWebApplicationFactory
, which is something you might require depending on your scenario. - The tests in
DemoTest1
andDemoTest2
can NOT run in parallel. This is because the Serilog logger is setup on a static global property. That's why both test classes are marked with aCollection
attribute. In xUnit that's how you control the parallelism of running tests.