Output logs to the console via Serilog in the ASP. NET Core Integration test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.