asp.net core 多端口监听&日志服务
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 日志服务
Telemetry 日志服务
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();
}
只要有访问就会记录下日志
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服务
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 多端口监听&日志服务的更多相关文章
- ASP.NET Core中配置监听URLs的五种方式
		
原文: 5 ways to set the URLs for an ASP.NET Core app 作者: Andrew Lock 译者: Lamond Lu 默认情况下,ASP. NET Core ...
 - ORACLE清理、截断监听日志文件(listener.log)
		
在ORACLE数据库中,如果不对监听日志文件(listener.log)进行截断,那么监听日志文件(listener.log)会变得越来越大,想必不少人听说过关于"LISTENER.LOG日 ...
 - ZooKeeper(二):多个端口监听的建立逻辑解析
		
ZooKeeper 作为优秀的分布系统协调组件,值得一探究竟.它的启动类主要为: 1. 单机版的zk 使用 ZooKeeperServerMain 2. 集群版的zk 使用 QuorumPeerMai ...
 - nodejs 80端口监听失败及NODE_PATH不起作用的问题
		
nodejs做web服务器,打开80时报错:Error: listen EACCES 0.0.0.0:80 80端口监听失败,是因为1024以下的端口需要root权限,需要sudo或su之后执行.但这 ...
 - ORACLE 监听日志文件太大停止写监听日志引起数据库连接不上问题
		
生产库监听日志文件太大(达到4G多),发现oracle停止写监听日志,检查参数log_file,log_directory,log_status 均正常,数据库运行也正常. 经确认确实为监听日志过大引 ...
 - ORACLE的监听日志太大,客户端无法连接
		
数据库sqlplus能连接,plsql连接失败,也不报错,就定位到了是不是监听出了什么问题,删除监听,重建监听,重启监听,各种尝试都没解决问题. 却是监听日志太大导致的问题,一下是处理步骤: 查看监听 ...
 - oracle 登录数据库时报 无监听 的一种解决方式(监听日志文件达到4g默认上限)
		
问题:登录服务器时 报无监听服务 检查步骤: 1.进入sqlplus查看数据库的状态,显示当前数据库的状态为OPEN 脚本:select status from v$Instance; 2.检查数据库 ...
 - asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程
		
最近在学习张善友老师的NanoFabric 框架的时了解到Exceptionless : https://exceptionless.com/ !因此学习了一下这个开源框架!下面对Exceptionl ...
 - asp.net core自定义端口
		
asp.net Core 自定义端口 官方文档 aspnet内库源码: https://github.com/aspnet dotnet系统内库源码:https://github.com/dotnet ...
 
随机推荐
- adobe acrobat x pro破解版
			
adobe acrobat x pro破解版是Adobe官方出品的PDF文档全能解决方案套件. PDF文件格式是Adobe公司设计的,用其公司开发的Adobe Acrobat X Pro来创建.编辑. ...
 - python爬虫小结1
			
先看正则化,正则化就是描述命令和字符切分.查找.筛选等功能的方便方式. http://www.cnblogs.com/fnng/archive/2013/05/20/3089816.html 一个游戏 ...
 - jQuery对表单元素的取值和赋值操作代码(转)
			
使用常规的思路:$("#keyword").value 取值是取不到的,因为此时$('#keydord')已经不是个element,而是个jquery对象,所以应该使用:$(&qu ...
 - mongodb命令行基础语法
			
首先是安装并配置mongodb,这个请自行百度,安装完成后打开cmd命令输入mongo.我们现在先做一个例子吧,假设有一个班级叫c1,里面有若干个人,里面的人有姓名.年龄.性别和班级,我们分别对他们进 ...
 - VMware的一些总结
			
一.虚拟主机联网的三种方式: 1.仅主机(Host Only),虚拟主机只能与宿主机联网通信,无法访问外网和宿主机所在局域网的其它主机. 2.桥接(Bridge),在桥接模式下,虚拟主机就像是宿主机所 ...
 - GitLab配置ssh key
			
一.背景 当前很多公司都选择git作为代码版本控制工具,然后自己公司搭建私有的gitlab来管理代码,我们在clone代码的时候可以选择http协议,当然我们亦可以选择ssh协议来拉取代码.但是网上很 ...
 - js获取图片的EXIF,解决图片旋转问题
			
相信大家在做项目的时候会遇到在canvas里加入图片时,图片发生90°,180°的旋转.当时的你肯定时懵逼的,为毛. 其实这就是图片的EXIF搞的鬼. 什么是EXIF 简单来说,Exif 信息就是由数 ...
 - 模板引擎(smarty)知识点总结II
			
今天咱们继续来学习smarty!!! 知识点1:对于三种变量 常量的引用 有哪三种变量?a.assign赋值 b.系统保留变量(包括:$smarty.get,$smarty.post,$smarty. ...
 - 实体框架(Entity Frmaework)简介
			
l简称EF NH l与Asp.Net MVC关系与ADO.NET关系 lADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapp ...
 - PHP    call_user_func
			
<?php function my_call_back_function(){ echo "hello world!"; } class MyClass{ static fu ...