The log is the programmer's radar, not only in the production environment, but also in the integrated test environment, which helps to locate the problem after continuous integration fails. Unlike a production environment, it is more convenient to use the console output log in an integrated test environment, so that you can see the logs through the output of the continuous integration runner execution job.
This blog post simply records our implementation code for outputting logs to the console via Serilog in the ASP. NET Core Integration test
varOutputtemplate ="{TIMESTAMP:HH:MM:SS.FFF} [{Level:u3}] {sourcecontext}{newline}{message}{newline}{exception}"; Log.logger=Newloggerconfiguration (). Minimumlevel.information (). Minimumlevel.override ("Microsoft.entityframeworkcore", Logeventlevel.debug). Writeto.console (outputtemplate:outputtemplate). Createlogger (); Iwebhostbuilder Webhostbuilder=Webhost.createdefaultbuilder (). Usestartup<Startup>() . Useserilog (); TestServer=NewTestServer (Webhostbuilder);
The outputtemplate is defined to add {Sourcecontext} to implement the class name in the log, as described in. NET core how to let the Serilog log display the class name like a console log
Writeto.console is to have serilog output logs to the console.
The required NuGet packages:
<ItemGroup> <packagereferenceInclude= "Serilog"Version= "2.7.1" /> <packagereferenceInclude= "Serilog.aspnetcore"Version= "2.1.1" /> <packagereferenceInclude= "Serilog.Sinks.Console"Version= "3.1.1" /></ItemGroup>
Output logs to the console via Serilog in the ASP. NET Core Integration test