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 ...
随机推荐
- .NET 实现Base-64加密解密处理
.NET 实现Base-64加密解密处理 using System; using System.Collections.Generic; using System.Linq; using System ...
- 微信小程序——微信支付
这个讲起来也就比较麻烦一点,因为需要的不仅仅是咱们代码上的技术,嘿嘿! 先整理一下思路.如果想做微信支付: 1.现有一个公司账户(非个人账户),并且实名认证过的. 2.微信号 必须开通微信支付功能. ...
- 【maven教程】(1)---maven环境配置
maven环境配置 刚开始学习maven,现在项目需要用到maven,而且他确实很好用,也比较容易上手,我也是主要通过视频学习,在写博客的时候也会总结其它人所写 博客,从简到难,如果你也是初学者那接下 ...
- Android开发——导入github安卓项目源码
之前在Github上看见其他人的安卓项目源码,便是想下载源码来学习学习,但是下载之后一直导入失败,经过了漫长的摸索终于是成功了,便是分享一下经验 首先进入Github官网,找到想要学习的安卓源码 右上 ...
- Struts2学习---namespace,file模块包含,默认action
我们上一节已经将action基本的配置和使用讲了,接下来我们讲以下struts一些小知识点: namespac: 上一节学习action的时候我们访问我们jsp文件时候使用的: http://loca ...
- [array] leetcode - 35. Search Insert Position - Easy
leetcode - 35. Search Insert Position - Easy descrition Given a sorted array and a target value, ret ...
- Hybris 项目工程配置
1.控制台页面进入platform目录 cd F:\hybris640\hybris\bin\platform 并运行 setantenv.bat 生成对应的ant. 2.运行 ant moduleg ...
- <!--[if lte IE 8][endif] ]-->IE下判断IE版本的语句
<!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![endif]--> ...
- layer遮罩层 简单的遮罩层
在这里提供一个简单layer遮罩层,想深入了解可以进入 layer官网 多多学习哦. 先看下HTML页面代码 <!DOCTYPE html> <html lang="en& ...
- DNS查询的工作原理
二.DNS查询的工作原理 1.DNS查询过程按两部分进行 1.名称查询从客户端计算机开始, 并传送给本机的DNS客户服务程序进行解析 2.如果不能再本机解析查询, 可根据设定的查询DN ...