asp.net core tips

來源:互聯網
上載者:User

標籤:mic   console   ice   分享   sof   art   config   內建   UI   

1 配置多個連接埠監聽

HostingAbstractionsWebHostBuilderExtensions.

public static IWebHostBuilder UseUrls(this IWebHostBuilder hostBuilder, params string[] urls);

 

 

 

 

 

運行結果:

 

 

 

 

 

 

2 使用配置把多連接埠放到設定檔中

 

添加設定檔

hosting.json

{

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

}

 

讀取配置 var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("hosting.json", optional:true).Build(); 設定配置: var host = new WebHostBuilder().UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).UseIISIntegration()//可以設定多個監聽連接埠,http://localhost:5000/ http://localhost:6001/ 都是可以訪問的//.UseUrls("http://*:5000","http://*:6001")//添加的多連接埠設定放到配置中.UseConfiguration(config).UseStartup < Startup > ().Build();host.Run(); 

 

 

 

 

3 .net Core Log Service

 

Telemetry Log Service

 

public void ConfigureServices(IServiceCollection services){// Add framework services.services.AddApplicationInsightsTelemetry(Configuration); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){loggerFactory.AddConsole(Configuration.GetSection("Logging"));loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry();} 

 

 

只要有訪問就會記錄下日誌

 

http://localhost:6001/

 

Log 日誌

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":"200","url":"http://localhost:6001/","httpMethod":"GET","properties":{"DeveloperMode":"true"}}}}

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

=

 

 

關閉 Telemetry Log Service

 

http://localhost:6001/

內建的Log服務

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 200 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 200 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)

{

//配置ConsoleLog服務loggerFactory.AddConsole(Configuration.GetSection("Logging"));//設定服務輸出層級//Debug 層級會輸出包括Information層級的所有日誌loggerFactory.AddDebug();}

 

 

 

 

 

 

 

 

 

 

 

 

 

asp.net core tips

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.