ASP. NET Core Tips

Source: Internet
Author: User

1 Configuring multiple port monitoring

Hostingabstractionswebhostbuilderextensions.

public static Iwebhostbuilder Useurls (this iwebhostbuilder hostbuilder, params string[] URLs);

Operation Result:

2 using configurations to place multiple ports in a configuration file

Add a configuration file

Hosting.json

{

"Server.urls": "http://localhost:6001;http://localhost:5000"

}

Read ConfigurationvarConfig =NewConfigurationbuilder (). Setbasepath (Directory.GetCurrentDirectory ()). Addjsonfile ("Hosting.json", Optional:true). Build (); To set the configuration:varHost =NewWebhostbuilder (). Usekestrel (). Usecontentroot (Directory.GetCurrentDirectory ()). Useiisintegration ()//you can set up multiple listening ports,http://localhost: 5000/http://localhost: 6001/both accessible//. Useurls ("http://*:5000 "," http://*:6001 ")//add multi-port settings to the configuration. Useconfiguration (config). Usestartup< Startup > (). Build (); host. Run (); 

3. NET Core Log service

Telemetry Log Service

 Public void configureservices (iservicecollection services) {//  ADD Framework services.  publicvoid  Configure (Iapplicationbuilder app, Ihostingenvironment env, Iloggerfactory loggerfactory) {loggerfactory.addconsole (configuration.getsection ("Logging "

The log will be recorded as soon as there is access.

http://localhost:6001/

Log logs

Application Insights Telemetry (unconfigured): {"name": "Microsoft.ApplicationInsights.Dev.Request", "Time": " 2017-08-05t09:11:22.6148689z "," tags ": {" ai.device.roleInstance ":" lihongbo-pc "," ai.internal.sdkVersion ":" aspnet5c:1.0.0 "," Ai.operation.name ":" GET/"," ai.operation.id ":" oubk/2md5ns= "," ai.user.userAgent ":" mozilla/5.0 ( Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/60.0.3112.78 safari/537.36 "}," data ": {" BaseType ":" RequestData "," Basedata ": {" ver ": 2," id ":" oubk/2md5ns= "," name ":" GET/"," StartTime ":" 2017-08-05t09:11:22.6148689+00:00 "," duration ":" 00:00:00.1031536 "," Success ": true," Responsecode ":" $ "," url ":" http://localhost:6001/"," HttpMethod ":" GET "," Properties ": {" DeveloperMode ":" True "}}}

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information:Request finished in 343.1286ms text/html; Charset=utf-8

=

Close Telemetry Log service

http://localhost:6001/

Log service with your own

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information:Request starting http/1.1 GET http://localhost:6001/

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information:Request finished in 8.2399ms text/html; Charset=utf-8

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information:Request starting http/1.1 GET http://localhost:6001/

Microsoft.AspNetCore.Hosting.Internal.WebHost:information: Request finished in 4.3987ms text/html; Charset=utf-8

This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

public void Configure (Iapplicationbuilder app, Ihostingenvironment env, Iloggerfactory loggerfactory)

{

// Configuring the ConsoleLog service Loggerfactory.addconsole (configuration.getsection ("Logging")); // Setting the service output level // the Debug level outputs all logs that include the information level loggerfactory.adddebug ();}

ASP. NET Core Tips

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.