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 ...
随机推荐
- [转载]ArchLinux 添加 archlinuxcn 源 密钥错误
http://www.jianshu.com/p/8ed688b0a096 杜龙少 正在检查密钥环里的密钥 [######################] 100% 正在下载所需的密钥...... ...
- redis集群配置,spring整合jedis,缓存同步
前台的商品数据(图片等加载缓慢)查询,先从redis缓存查询数据. redis是一个nosql数据库,内存版数据库,读取速度11w/s.本身具有内存淘汰机制,是单线程服务器(分时操作系统),线程安全. ...
- lua中怎么替换掉字符串中的$^特殊字符?
Lua 常规替换字符串如何替换 s = string.gsub("Lua is good", "good", "bad") print(s) ...
- spring boot https --restful接口篇
我们写的接口默认都是http形式的,不过我们的接口很容易被人抓包,而且一抓全是明文的挺尴尬的 spring boot配置https生成证书大的方向有3种: 1.利用keytool自己生成证书 2.从免 ...
- MySQL时间操作的系统函数用法
我要查询获得当天凌晨30分的datetime值的方式:select ADDDATE(CURDATE(), INTERVAL TIME_TO_SEC(TIMEDIFF("00:30:00&qu ...
- 'boost/iterator/iterator_adaptor.hpp' file not found之xcode生成时报错的解决方案
xcode生成rn(0.49.3)项目的时候出现“'boost/iterator/iterator_adaptor.hpp' file not found之xcode”报错. 原因: /Users/x ...
- [Upper case conversion ] 每个单词的首小写字母转换为对应的大写字母
Given a string , write a program to title case every first letter of words in string. Input:The firs ...
- Android SDK Manager配置
Android SDK Manager就是一个Android软件开发工具包管理器,就像一个桥梁,连通本地和服务器,从服务器下载安卓开发所需工具到本地. 而AVD Manager是一个Android虚拟 ...
- 一种优雅的条件引用第三方.net库的方法
1.遇到的问题 今年我一直在开发一个WebApiClient库,旨在.net下能像java的retrofit一样,方便地请求服务端的http接口.在这restful api盛行的年代,json的身影无 ...
- 微信小程序开发教程目录
本系列教程是自己在工作中使用到而记录的,没有顺序之分 如有错误之处,请给与指正,也不希望误导了别人 微信小程序开发教程目录 微信小程序之注册和入门 微信小程序之HTTPS请求 微信小程序开发之选项卡 ...