From 1be90f1bc54d10a656546f6acda99da782f067c9 Mon Sep 17 00:00:00 2001 From: Linlccc <1610450962@qq.com> Date: Wed, 2 Mar 2022 15:01:17 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=201.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20program=20=E5=8F=AF=E8=AF=BB=E6=80=A7=202.=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84=20appsettings=20=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 1.让配置文件更具可读性,根据功能等信息分类;不同环境配置更加清晰 2.直接配置需要加入的自定义配置文件夹,自动完成配置添加 3.不同环境时只需配置一次appsettings.[EnvironmentName].json文件即可,不用频繁的在不同环境中修改大量的配置信息 --- Blog.Core.Api/Blog.Core.Api.csproj | 1 + Blog.Core.Api/Blog.Core.xml | 6 - .../Apollo.json} | 4 +- Blog.Core.Api/CustomConfig/AppSettings.json | 34 ++ Blog.Core.Api/CustomConfig/Audience.json | 8 + Blog.Core.Api/CustomConfig/ConsulSetting.json | 9 + Blog.Core.Api/CustomConfig/Db.json | 80 +++++ Blog.Core.Api/CustomConfig/EventBus.json | 6 + .../CustomConfig/IpRateLimiting.json | 40 +++ Blog.Core.Api/CustomConfig/Kafka.json | 9 + Blog.Core.Api/CustomConfig/LogFiedOutPut.json | 12 + Blog.Core.Api/CustomConfig/Middleware.json | 26 ++ Blog.Core.Api/CustomConfig/Mongo.json | 6 + Blog.Core.Api/CustomConfig/Nacos.json | 11 + Blog.Core.Api/CustomConfig/Pay.json | 11 + Blog.Core.Api/CustomConfig/RabbitMQ.json | 9 + Blog.Core.Api/CustomConfig/Redis.json | 5 + Blog.Core.Api/CustomConfig/Startup.json | 29 ++ .../DevelopmentCustomConfig/Apollo.json | 18 ++ .../DevelopmentCustomConfig/AppSettings.json | 34 ++ .../DevelopmentCustomConfig/Audience.json | 8 + .../ConsulSetting.json | 9 + Blog.Core.Api/DevelopmentCustomConfig/Db.json | 80 +++++ .../DevelopmentCustomConfig/EventBus.json | 6 + .../IpRateLimiting.json | 40 +++ .../DevelopmentCustomConfig/Kafka.json | 9 + .../LogFiedOutPut.json | 12 + .../DevelopmentCustomConfig/Middleware.json | 26 ++ .../DevelopmentCustomConfig/Mongo.json | 6 + .../DevelopmentCustomConfig/Nacos.json | 11 + .../DevelopmentCustomConfig/Pay.json | 11 + .../DevelopmentCustomConfig/RabbitMQ.json | 9 + .../DevelopmentCustomConfig/Redis.json | 5 + .../DevelopmentCustomConfig/Startup.json | 29 ++ Blog.Core.Api/Program.cs | 76 ++--- Blog.Core.Api/Properties/launchSettings.json | 2 +- Blog.Core.Api/Startup.cs | 1 - Blog.Core.Api/appsettings.Development.json | 43 ++- Blog.Core.Api/appsettings.backup.json | 305 ++++++++++++++++++ Blog.Core.Api/appsettings.json | 269 +-------------- Blog.Core.Common/Blog.Core.Common.csproj | 1 + Blog.Core.Common/Helper/Appsettings.cs | 127 +++++++- .../Apollo/ConfigurationBuilderExtensions.cs | 2 +- .../ServiceExtensions/AppConfigSetup.cs | 2 - .../CustomConfig/ApiGateWay.json | 11 + Blog.Core.Gateway/CustomConfig/Audience.json | 8 + Blog.Core.Gateway/CustomConfig/BlackList.json | 5 + Blog.Core.Gateway/CustomConfig/Influxdb.json | 8 + Blog.Core.Gateway/CustomConfig/Nacos.json | 31 ++ .../Ocelot.json} | 0 Blog.Core.Gateway/CustomConfig/Startup.json | 9 + Blog.Core.Gateway/CustomConfig/WhiteList.json | 8 + .../CustomConfig/nacosConfig.json | 19 ++ .../DevelopmentCustomConfig/ApiGateWay.json | 11 + .../DevelopmentCustomConfig/Audience.json | 8 + .../DevelopmentCustomConfig/BlackList.json | 5 + .../DevelopmentCustomConfig/Influxdb.json | 8 + .../DevelopmentCustomConfig/Nacos.json | 31 ++ .../DevelopmentCustomConfig/Ocelot.json | 59 ++++ .../DevelopmentCustomConfig/Startup.json | 9 + .../DevelopmentCustomConfig/WhiteList.json | 8 + .../DevelopmentCustomConfig/nacosConfig.json | 19 ++ .../Helper/CustomJwtTokenAuthMiddleware.cs | 2 +- Blog.Core.Gateway/Program.cs | 8 +- Blog.Core.Gateway/Startup.cs | 2 - .../appsettings.Development.json | 11 + Blog.Core.Gateway/appsettings.Production.json | 12 + Blog.Core.Gateway/appsettings.Staging.json | 12 + Blog.Core.Gateway/appsettings.backup.json | 104 ++++++ Blog.Core.Gateway/appsettings.json | 95 +----- Blog.Core.Gateway/ocelot.Production.json | 3 - Blog.Core.Gateway/ocelot.Staging.json | 3 - Blog.Core.Gateway/ocelot.json | 3 - .../DependencyInjection/DI_Test.cs | 2 +- 74 files changed, 1515 insertions(+), 446 deletions(-) rename Blog.Core.Api/{appsettings.apollo.json => CustomConfig/Apollo.json} (74%) create mode 100644 Blog.Core.Api/CustomConfig/AppSettings.json create mode 100644 Blog.Core.Api/CustomConfig/Audience.json create mode 100644 Blog.Core.Api/CustomConfig/ConsulSetting.json create mode 100644 Blog.Core.Api/CustomConfig/Db.json create mode 100644 Blog.Core.Api/CustomConfig/EventBus.json create mode 100644 Blog.Core.Api/CustomConfig/IpRateLimiting.json create mode 100644 Blog.Core.Api/CustomConfig/Kafka.json create mode 100644 Blog.Core.Api/CustomConfig/LogFiedOutPut.json create mode 100644 Blog.Core.Api/CustomConfig/Middleware.json create mode 100644 Blog.Core.Api/CustomConfig/Mongo.json create mode 100644 Blog.Core.Api/CustomConfig/Nacos.json create mode 100644 Blog.Core.Api/CustomConfig/Pay.json create mode 100644 Blog.Core.Api/CustomConfig/RabbitMQ.json create mode 100644 Blog.Core.Api/CustomConfig/Redis.json create mode 100644 Blog.Core.Api/CustomConfig/Startup.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Apollo.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Audience.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Db.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/EventBus.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Kafka.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Middleware.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Mongo.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Nacos.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Pay.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Redis.json create mode 100644 Blog.Core.Api/DevelopmentCustomConfig/Startup.json create mode 100644 Blog.Core.Api/appsettings.backup.json create mode 100644 Blog.Core.Gateway/CustomConfig/ApiGateWay.json create mode 100644 Blog.Core.Gateway/CustomConfig/Audience.json create mode 100644 Blog.Core.Gateway/CustomConfig/BlackList.json create mode 100644 Blog.Core.Gateway/CustomConfig/Influxdb.json create mode 100644 Blog.Core.Gateway/CustomConfig/Nacos.json rename Blog.Core.Gateway/{ocelot.Development.json => CustomConfig/Ocelot.json} (100%) create mode 100644 Blog.Core.Gateway/CustomConfig/Startup.json create mode 100644 Blog.Core.Gateway/CustomConfig/WhiteList.json create mode 100644 Blog.Core.Gateway/CustomConfig/nacosConfig.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json create mode 100644 Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json create mode 100644 Blog.Core.Gateway/appsettings.Production.json create mode 100644 Blog.Core.Gateway/appsettings.Staging.json create mode 100644 Blog.Core.Gateway/appsettings.backup.json delete mode 100644 Blog.Core.Gateway/ocelot.Production.json delete mode 100644 Blog.Core.Gateway/ocelot.Staging.json delete mode 100644 Blog.Core.Gateway/ocelot.json diff --git a/Blog.Core.Api/Blog.Core.Api.csproj b/Blog.Core.Api/Blog.Core.Api.csproj index b5725edd..d53a9729 100644 --- a/Blog.Core.Api/Blog.Core.Api.csproj +++ b/Blog.Core.Api/Blog.Core.Api.csproj @@ -22,6 +22,7 @@ false + disable diff --git a/Blog.Core.Api/Blog.Core.xml b/Blog.Core.Api/Blog.Core.xml index 32ac8c50..f4c1efcc 100644 --- a/Blog.Core.Api/Blog.Core.xml +++ b/Blog.Core.Api/Blog.Core.xml @@ -1250,11 +1250,5 @@ 全局路由前缀公约 - - - 根据环境变量定向配置文件名称 - - - diff --git a/Blog.Core.Api/appsettings.apollo.json b/Blog.Core.Api/CustomConfig/Apollo.json similarity index 74% rename from Blog.Core.Api/appsettings.apollo.json rename to Blog.Core.Api/CustomConfig/Apollo.json index 826c75ca..27e01459 100644 --- a/Blog.Core.Api/appsettings.apollo.json +++ b/Blog.Core.Api/CustomConfig/Apollo.json @@ -1,5 +1,5 @@ { - //apollo 配置 + //apollo "Apollo": { "Enable": false, "Config": { @@ -8,7 +8,7 @@ "MetaServer": "http://localhost:8080/", "ConfigServer": [ "http://localhost:8080/" ] }, - "Namespaces": [ //Namespaces的数据格式Properties,Xml,Json,Yml,Yaml,Txt + "Namespaces": [ //NamespacesݸʽProperties,Xml,Json,Yml,Yaml,Txt { "Name": "test", "Format": "json" diff --git a/Blog.Core.Api/CustomConfig/AppSettings.json b/Blog.Core.Api/CustomConfig/AppSettings.json new file mode 100644 index 00000000..92043539 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/AppSettings.json @@ -0,0 +1,34 @@ +{ + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": false + }, + "TranAOP": { + "Enabled": false + }, + "SqlAOP": { + "Enabled": true, + "OutToLogFile": { + "Enabled": false + }, + "OutToConsole": { + "Enabled": true + } + }, + "LogToDb": { + "Enabled": true + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + } +} diff --git a/Blog.Core.Api/CustomConfig/Audience.json b/Blog.Core.Api/CustomConfig/Audience.json new file mode 100644 index 00000000..f104c6f9 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + } +} diff --git a/Blog.Core.Api/CustomConfig/ConsulSetting.json b/Blog.Core.Api/CustomConfig/ConsulSetting.json new file mode 100644 index 00000000..9c65d8ef --- /dev/null +++ b/Blog.Core.Api/CustomConfig/ConsulSetting.json @@ -0,0 +1,9 @@ +{ + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + } +} diff --git a/Blog.Core.Api/CustomConfig/Db.json b/Blog.Core.Api/CustomConfig/Db.json new file mode 100644 index 00000000..ad17697c --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Db.json @@ -0,0 +1,80 @@ +{ + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ] +} diff --git a/Blog.Core.Api/CustomConfig/EventBus.json b/Blog.Core.Api/CustomConfig/EventBus.json new file mode 100644 index 00000000..4f4589f8 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/EventBus.json @@ -0,0 +1,6 @@ +{ + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + } +} diff --git a/Blog.Core.Api/CustomConfig/IpRateLimiting.json b/Blog.Core.Api/CustomConfig/IpRateLimiting.json new file mode 100644 index 00000000..9ca9f535 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/IpRateLimiting.json @@ -0,0 +1,40 @@ +{ + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + } +} diff --git a/Blog.Core.Api/CustomConfig/Kafka.json b/Blog.Core.Api/CustomConfig/Kafka.json new file mode 100644 index 00000000..a7ddcaac --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Kafka.json @@ -0,0 +1,9 @@ +{ + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + } +} diff --git a/Blog.Core.Api/CustomConfig/LogFiedOutPut.json b/Blog.Core.Api/CustomConfig/LogFiedOutPut.json new file mode 100644 index 00000000..32182dd1 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/LogFiedOutPut.json @@ -0,0 +1,12 @@ +{ + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/CustomConfig/Middleware.json b/Blog.Core.Api/CustomConfig/Middleware.json new file mode 100644 index 00000000..710da3c3 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Middleware.json @@ -0,0 +1,26 @@ +{ + "Middleware": { + "RequestResponseLog": { + "Enabled": false + }, + "IPLog": { + "Enabled": true + }, + "RecordAccessLogs": { + "Enabled": true, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + } +} diff --git a/Blog.Core.Api/CustomConfig/Mongo.json b/Blog.Core.Api/CustomConfig/Mongo.json new file mode 100644 index 00000000..60b11e95 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Mongo.json @@ -0,0 +1,6 @@ +{ + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + } +} diff --git a/Blog.Core.Api/CustomConfig/Nacos.json b/Blog.Core.Api/CustomConfig/Nacos.json new file mode 100644 index 00000000..a369d76b --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Nacos.json @@ -0,0 +1,11 @@ +{ + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + } +} \ No newline at end of file diff --git a/Blog.Core.Api/CustomConfig/Pay.json b/Blog.Core.Api/CustomConfig/Pay.json new file mode 100644 index 00000000..fd4e77e6 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Pay.json @@ -0,0 +1,11 @@ +{ + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + } +} diff --git a/Blog.Core.Api/CustomConfig/RabbitMQ.json b/Blog.Core.Api/CustomConfig/RabbitMQ.json new file mode 100644 index 00000000..7b77640a --- /dev/null +++ b/Blog.Core.Api/CustomConfig/RabbitMQ.json @@ -0,0 +1,9 @@ +{ + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + } +} diff --git a/Blog.Core.Api/CustomConfig/Redis.json b/Blog.Core.Api/CustomConfig/Redis.json new file mode 100644 index 00000000..224f3140 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Redis.json @@ -0,0 +1,5 @@ +{ + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + } +} diff --git a/Blog.Core.Api/CustomConfig/Startup.json b/Blog.Core.Api/CustomConfig/Startup.json new file mode 100644 index 00000000..accd3ce1 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Startup.json @@ -0,0 +1,29 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json new file mode 100644 index 00000000..27e01459 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json @@ -0,0 +1,18 @@ +{ + //apollo + "Apollo": { + "Enable": false, + "Config": { + "AppId": "blog.core", + "Env": "DEV", + "MetaServer": "http://localhost:8080/", + "ConfigServer": [ "http://localhost:8080/" ] + }, + "Namespaces": [ //NamespacesݸʽProperties,Xml,Json,Yml,Yaml,Txt + { + "Name": "test", + "Format": "json" + } + ] + } +} \ No newline at end of file diff --git a/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json new file mode 100644 index 00000000..92043539 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json @@ -0,0 +1,34 @@ +{ + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": false + }, + "TranAOP": { + "Enabled": false + }, + "SqlAOP": { + "Enabled": true, + "OutToLogFile": { + "Enabled": false + }, + "OutToConsole": { + "Enabled": true + } + }, + "LogToDb": { + "Enabled": true + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Audience.json b/Blog.Core.Api/DevelopmentCustomConfig/Audience.json new file mode 100644 index 00000000..f104c6f9 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json b/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json new file mode 100644 index 00000000..9c65d8ef --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json @@ -0,0 +1,9 @@ +{ + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Db.json b/Blog.Core.Api/DevelopmentCustomConfig/Db.json new file mode 100644 index 00000000..ad17697c --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Db.json @@ -0,0 +1,80 @@ +{ + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ] +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json b/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json new file mode 100644 index 00000000..4f4589f8 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json @@ -0,0 +1,6 @@ +{ + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json b/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json new file mode 100644 index 00000000..9ca9f535 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json @@ -0,0 +1,40 @@ +{ + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json b/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json new file mode 100644 index 00000000..a7ddcaac --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json @@ -0,0 +1,9 @@ +{ + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json b/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json new file mode 100644 index 00000000..32182dd1 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json @@ -0,0 +1,12 @@ +{ + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json new file mode 100644 index 00000000..710da3c3 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json @@ -0,0 +1,26 @@ +{ + "Middleware": { + "RequestResponseLog": { + "Enabled": false + }, + "IPLog": { + "Enabled": true + }, + "RecordAccessLogs": { + "Enabled": true, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json b/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json new file mode 100644 index 00000000..60b11e95 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json @@ -0,0 +1,6 @@ +{ + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json b/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json new file mode 100644 index 00000000..a369d76b --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json @@ -0,0 +1,11 @@ +{ + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + } +} \ No newline at end of file diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Pay.json b/Blog.Core.Api/DevelopmentCustomConfig/Pay.json new file mode 100644 index 00000000..fd4e77e6 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Pay.json @@ -0,0 +1,11 @@ +{ + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json b/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json new file mode 100644 index 00000000..7b77640a --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json @@ -0,0 +1,9 @@ +{ + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Redis.json b/Blog.Core.Api/DevelopmentCustomConfig/Redis.json new file mode 100644 index 00000000..224f3140 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Redis.json @@ -0,0 +1,5 @@ +{ + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Startup.json b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json new file mode 100644 index 00000000..accd3ce1 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json @@ -0,0 +1,29 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + } +} diff --git a/Blog.Core.Api/Program.cs b/Blog.Core.Api/Program.cs index 9e416297..492e0d6b 100644 --- a/Blog.Core.Api/Program.cs +++ b/Blog.Core.Api/Program.cs @@ -1,4 +1,5 @@ using Autofac.Extensions.DependencyInjection; +using Blog.Core.Common; using Blog.Core.Extensions.Apollo; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -15,60 +16,35 @@ public static void Main(string[] args) { //初始化默认主机Builder Host.CreateDefaultBuilder(args) - .UseServiceProviderFactory(new AutofacServiceProviderFactory()) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder - .UseStartup() - .ConfigureAppConfiguration((hostingContext, config) => - { - config.Sources.Clear(); - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) - //.AddJsonFile($"appsettings{ GetAppSettingsConfigName() }json", optional: true, reloadOnChange: false) - ; - //接入Apollo配置中心 - config.AddConfigurationApollo("appsettings.apollo.json"); - }) - .UseUrls("http://*:9291") - .ConfigureLogging((hostingContext, builder) => - { - // 1.过滤掉系统默认的一些日志 - builder.AddFilter("System", LogLevel.Error); - builder.AddFilter("Microsoft", LogLevel.Error); + // 配置应用程序 自定义添加配置信息 + .ConfigureAppConfiguration(Appsettings.AddConfigureFiles) + //接入Apollo配置中心 + .ConfigureAppConfiguration((_, config) => config.AddConfigurationApollo()) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .ConfigureLogging((hostingContext, builder) => + { + // 1.过滤掉系统默认的一些日志 + builder.AddFilter("System", LogLevel.Error); + builder.AddFilter("Microsoft", LogLevel.Error); - // 2.也可以在appsettings.json中配置,LogLevel节点 + // 2.也可以在appsettings.json中配置,LogLevel节点 - // 3.统一设置 - builder.SetMinimumLevel(LogLevel.Error); + // 3.统一设置 + builder.SetMinimumLevel(LogLevel.Error); - // 默认log4net.confg - builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config")); + // 默认log4net.confg + builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config")); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup() + .UseUrls("http://*:9291"); }) - ; - }) - // 生成承载 web 应用程序的 Microsoft.AspNetCore.Hosting.IWebHost。Build是WebHostBuilder最终的目的,将返回一个构造的WebHost,最终生成宿主。 - .Build() - // 运行 web 应用程序并阻止调用线程, 直到主机关闭。 - // ※※※※ 有异常,查看 Log 文件夹下的异常日志 ※※※※ - .Run(); - } - - - /// - /// 根据环境变量定向配置文件名称 - /// - /// - private static string GetAppSettingsConfigName() - { - if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != null - && Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != "") - { - return $".{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}."; - } - else - { - return "."; - } + // 生成承载 web 应用程序的 Microsoft.AspNetCore.Hosting.IWebHost。Build是WebHostBuilder最终的目的,将返回一个构造的WebHost,最终生成宿主。 + .Build() + // 运行 web 应用程序并阻止调用线程, 直到主机关闭。 + // ※※※※ 有异常,查看 Log 文件夹下的异常日志 ※※※※ + .Run(); } } } diff --git a/Blog.Core.Api/Properties/launchSettings.json b/Blog.Core.Api/Properties/launchSettings.json index 425ec45f..dc5b3c8c 100644 --- a/Blog.Core.Api/Properties/launchSettings.json +++ b/Blog.Core.Api/Properties/launchSettings.json @@ -1,4 +1,5 @@ { + "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, @@ -7,7 +8,6 @@ "sslPort": 0 } }, - "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "Blog.Core": { "commandName": "Project", diff --git a/Blog.Core.Api/Startup.cs b/Blog.Core.Api/Startup.cs index bc3d779f..343feda9 100644 --- a/Blog.Core.Api/Startup.cs +++ b/Blog.Core.Api/Startup.cs @@ -43,7 +43,6 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env) public void ConfigureServices(IServiceCollection services) { // 以下code可能与文章中不一样,对代码做了封装,具体查看右侧 Extensions 文件夹. - services.AddSingleton(new Appsettings(Configuration)); services.AddSingleton(new LogLock(Env.ContentRootPath)); services.AddUiFilesZipSetup(Env); diff --git a/Blog.Core.Api/appsettings.Development.json b/Blog.Core.Api/appsettings.Development.json index 9016c7ce..0bd28162 100644 --- a/Blog.Core.Api/appsettings.Development.json +++ b/Blog.Core.Api/appsettings.Development.json @@ -1,11 +1,36 @@ { - "nacos": { - "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 - "DefaultTimeOut": 15000, // 默认超时时间 - "Namespace": "public", // 命名空间 - "ListenInterval": 10000, // 监听的频率 - "ServiceName": "blog.Core.Api", // 服务名 - "Port": "9291", // 服务端口号 - "RegisterEnabled": true // 是否直接注册nacos + "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 + "Logging": { + "LogLevel": { + "Default": "Information", //加入Default否则log4net本地写入不了日志 + "Blog.Core.AuthHelper.ApiResponseHandler": "Error" + }, + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + }, + "Log4Net": { + "Name": "Blog.Core" + } + }, + "AllowedHosts": "*", + + // 自定义配置信息 + "CustomConfigInfo": { + /* + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 + */ + "ConfigFileFolders": [ "DevelopmentCustomConfig" ] } -} \ No newline at end of file +} diff --git a/Blog.Core.Api/appsettings.backup.json b/Blog.Core.Api/appsettings.backup.json new file mode 100644 index 00000000..4603a80d --- /dev/null +++ b/Blog.Core.Api/appsettings.backup.json @@ -0,0 +1,305 @@ +//之前的appsettings 备份 +{ + "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 + "Logging": { + "LogLevel": { + "Default": "Information", //加入Default否则log4net本地写入不了日志 + "Blog.Core.AuthHelper.ApiResponseHandler": "Error" + }, + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + }, + "Log4Net": { + "Name": "Blog.Core" + } + }, + "AllowedHosts": "*", + + // 自定义配置信息 + "CustomConfigInfo": { + /* + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 + */ + "ConfigFileFolders": [ "CustomConfig" ] + }, + + + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + }, + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + }, + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + }, + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + }, + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": false + }, + "TranAOP": { + "Enabled": false + }, + "SqlAOP": { + "Enabled": true, + "OutToLogFile": { + "Enabled": false + }, + "OutToConsole": { + "Enabled": true + } + }, + "LogToDb": { + "Enabled": true + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + }, + + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ], + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + }, + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + }, + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + }, + "Middleware": { + "RequestResponseLog": { + "Enabled": false + }, + "IPLog": { + "Enabled": true + }, + "RecordAccessLogs": { + "Enabled": true, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + }, + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + }, + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + }, + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + }, + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + }, + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/appsettings.json b/Blog.Core.Api/appsettings.json index 92d39d4d..b40e5b7d 100644 --- a/Blog.Core.Api/appsettings.json +++ b/Blog.Core.Api/appsettings.json @@ -22,270 +22,15 @@ } }, "AllowedHosts": "*", - "Redis": { - "ConnectionString": "127.0.0.1:6319,password=admin" - }, - "RabbitMQ": { - "Enabled": false, - "Connection": "118.25.251.13", - "UserName": "", - "Password": "!", - "RetryCount": 3 - }, - "Kafka": { - "Enabled": false, - "Servers": "localhost:9092", - "Topic": "blog", - "GroupId": "blog-consumer", - "NumPartitions": 3 //主题分区数量 - }, - "EventBus": { - "Enabled": false, - "SubscriptionClientName": "Blog.Core" - }, - "AppSettings": { - "RedisCachingAOP": { - "Enabled": false - }, - "MemoryCachingAOP": { - "Enabled": true - }, - "LogAOP": { - "Enabled": false - }, - "TranAOP": { - "Enabled": false - }, - "SqlAOP": { - "Enabled": true, - "OutToLogFile": { - "Enabled": false - }, - "OutToConsole": { - "Enabled": true - } - }, - "LogToDb": { - "Enabled": true - }, - "Date": "2018-08-28", - "SeedDBEnabled": true, //只生成表结构 - "SeedDBDataEnabled": true, //生成表,并初始化数据 - "Author": "Blog.Core", - "SvcName": "", // /svc/blog - "UseLoadTest": false - }, - // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; - // *** 单库操作,把 MutiDBEnabled 设为false ***; - // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; - // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 - - "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true - "MutiDBEnabled": false, //是否开启多库模式 - "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer - "DBS": [ + // 自定义配置信息 + "CustomConfigInfo": { /* - 对应下边的 DBType - MySql = 0, - SqlServer = 1, - Sqlite = 2, - Oracle = 3, - PostgreSQL = 4, - Dm = 5,//达梦 - Kdbndp = 6,//人大金仓 + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 */ - { - "ConnId": "WMBLOG_SQLITE", - "DBType": 2, - "Enabled": true, - "HitRate": 50, // 值越大,优先级越高 - "Connection": "WMBlog.db" //sqlite只写数据库名就行 - }, - { - "ConnId": "WMBLOG_MSSQL_1", - "DBType": 1, - "Enabled": false, - "HitRate": 40, - "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", - "ProviderName": "System.Data.SqlClient" - }, - { - "ConnId": "WMBLOG_MSSQL_2", - "DBType": 1, - "Enabled": false, - "HitRate": 30, - "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", - "ProviderName": "System.Data.SqlClient" - }, - { - "ConnId": "WMBLOG_MYSQL", - "DBType": 0, - "Enabled": false, - "HitRate": 20, - "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" - }, - { - "ConnId": "WMBLOG_MYSQL_2", - "DBType": 0, - "Enabled": true, - "HitRate": 20, - "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" - }, - { - "ConnId": "WMBLOG_ORACLE", - "DBType": 3, - "Enabled": false, - "HitRate": 10, - "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" - }, - { - "ConnId": "WMBLOG_DM", - "DBType": 5, - "Enabled": false, - "HitRate": 10, - "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" - }, - { - "ConnId": "WMBLOG_KDBNDP", - "DBType": 6, - "Enabled": true, - "HitRate": 10, - "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" - } - ], - "Audience": { - "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ - "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret - "Issuer": "Blog.Core", - "Audience": "wr" - }, - "Mongo": { - "ConnectionString": "mongodb://nosql.data", - "Database": "BlogCoreDb" - }, - "Startup": { - "Cors": { - "PolicyName": "CorsIpAccess", //策略名称 - "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 - // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 - // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364" - }, - "AppConfigAlert": { - "Enabled": true - }, - "ApiName": "Blog.Core", - "IdentityServer4": { - "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 - "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 - "ApiName": "blog.core.api" // 资源服务器 - }, - "RedisMq": { - "Enabled": false //redis 消息队列 - }, - "MiniProfiler": { - "Enabled": false //性能分析开启 - }, - "Nacos": { - "Enabled": false //Nacos注册中心 - } - }, - "Middleware": { - "RequestResponseLog": { - "Enabled": false - }, - "IPLog": { - "Enabled": true - }, - "RecordAccessLogs": { - "Enabled": true, - "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," - }, - "SignalR": { - "Enabled": false - }, - "QuartzNetJob": { - "Enabled": true - }, - "Consul": { - "Enabled": false - }, - "IpRateLimit": { - "Enabled": true - } - }, - "IpRateLimiting": { - "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each - "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter - "RealIpHeader": "X-Real-IP", - "ClientIdHeader": "X-ClientId", - "IpWhitelist": [], //白名单 - "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], - "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], - "QuotaExceededResponse": { - "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", - "ContentType": "application/json", - "StatusCode": 429 - }, - "HttpStatusCode": 429, //返回状态码 - "GeneralRules": [ //api规则,结尾一定要带* - { - "Endpoint": "*:/api/blog*", - "Period": "1m", - "Limit": 20 - }, - { - "Endpoint": "*/api/*", - "Period": "1s", - "Limit": 3 - }, - { - "Endpoint": "*/api/*", - "Period": "1m", - "Limit": 30 - }, - { - "Endpoint": "*/api/*", - "Period": "12h", - "Limit": 500 - } - ] - - }, - "ConsulSetting": { - "ServiceName": "BlogCoreService", - "ServiceIP": "localhost", - "ServicePort": "9291", - "ServiceHealthCheck": "/healthcheck", - "ConsulAddress": "http://localhost:8500" - }, - "PayInfo": { //建行聚合支付信息 - "MERCHANTID": "", //商户号 - "POSID": "", //柜台号 - "BRANCHID": "", //分行号 - "pubKey": "", //公钥 - "USER_ID": "", //操作员号 - "PASSWORD": "", //密码 - "OutAddress": "http://127.0.0.1:12345" //外联地址 - }, - "nacos": { - "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 - "DefaultTimeOut": 15000, // 默认超时时间 - "Namespace": "public", // 命名空间 - "ListenInterval": 10000, // 监听的频率 - "ServiceName": "blog.Core.Api", // 服务名 - "Port": "9291", // 服务端口号 - "RegisterEnabled": true // 是否直接注册nacos - }, - "LogFiedOutPutConfigs": { - "tcpAddressHost": "", // 输出elk的tcp连接地址 - "tcpAddressPort": 0, // 输出elk的tcp端口号 - "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 - { - "FiedName": "applicationName", - "FiedValue": "Blog.Core.Api" - } - ] + "ConfigFileFolders": ["CustomConfig"] } } diff --git a/Blog.Core.Common/Blog.Core.Common.csproj b/Blog.Core.Common/Blog.Core.Common.csproj index 1fb4ba6c..bb3949a4 100644 --- a/Blog.Core.Common/Blog.Core.Common.csproj +++ b/Blog.Core.Common/Blog.Core.Common.csproj @@ -2,6 +2,7 @@ net6.0 + disable diff --git a/Blog.Core.Common/Helper/Appsettings.cs b/Blog.Core.Common/Helper/Appsettings.cs index 0c970984..df5ce7a9 100644 --- a/Blog.Core.Common/Helper/Appsettings.cs +++ b/Blog.Core.Common/Helper/Appsettings.cs @@ -1,20 +1,22 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; +using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace Blog.Core.Common { - /// - /// appsettings.json操作类 - /// - public class Appsettings + + public static class Appsettings { + /// + /// 配置 + /// public static IConfiguration Configuration { get; set; } - static string contentPath { get; set; } - public Appsettings(string contentPath) + public static void Init(string contentPath) { string Path = "appsettings.json"; @@ -27,16 +29,88 @@ public Appsettings(string contentPath) .Build(); } - public Appsettings(IConfiguration configuration) + + /// + /// 添加配置文件 + /// + /// + /// + public static void AddConfigureFiles(HostBuilderContext hostBuilder, IConfigurationBuilder builder) { - Configuration = configuration; + //清除原配置,添加默认配置 + builder.Sources.Clear(); + GetDefaultConfigFiles().ForEach(file =>builder.AddJsonFile(file)); + + IConfigurationRoot configuration = builder.Build(); + // 获取自定义配置文件夹 && 文件夹存在 + IEnumerable customConfigFolder = configuration.Get>("CustomConfigInfo", "ConfigFileFolders")?.Where(folderPath => Directory.Exists(folderPath)); + if(customConfigFolder is null || !customConfigFolder.Any()) + { + Configuration = builder.Build(); + return; + } + + // 获取所有配置文件 + List jsonFiles = new(); + customConfigFolder.ToList().ForEach(folder => jsonFiles.AddRange(Directory.GetFiles(folder, "*.json", SearchOption.TopDirectoryOnly))); + + // 将配置文件添加到配置中 + jsonFiles.ForEach(jsonFile => builder.AddJsonFile(jsonFile, true, true)); + + Configuration = builder.Build(); + + + /// + /// 获取默认配置文件 + /// + /// + static List GetDefaultConfigFiles() + { + List configFiles = new() { "appsettings.json" }; + ; + string ASPNETCORE_ENVIRONMENT = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + if (ASPNETCORE_ENVIRONMENT?.Length > 0) configFiles.Add($"appsettings.{ASPNETCORE_ENVIRONMENT}.json"); + return configFiles; + } } + + #region 获取配置信息 + + /// + /// 判断节点是否存在 + /// + /// 配置 + /// 节点路径 + /// 节点存在返回 true,否者 false + public static bool Exists(params string[] sections) => Configuration.Exists(sections); + + /// + /// 读取节点字符串 + /// + /// 配置 + /// 节点路径 + /// 和节点路径匹配的字符串 + public static string Get(params string[] sections) => Configuration.Get(sections); + + /// + /// 读取节点并转换成指定类型 + /// + /// 返回的类型 + /// 配置 + /// 节点路径 + /// 和节点路径匹配的T类型对象 + public static T Get(params string[] sections) => Configuration.Get(sections); + + #endregion 获取配置信息 + + #region 以前获取配置信息 /// /// 封装要操作的字符 /// /// 节点配置 /// + [Obsolete("推荐使用 Git 方法")] public static string app(params string[] sections) { try @@ -58,6 +132,7 @@ public static string app(params string[] sections) /// /// /// + [Obsolete("推荐使用 Git 方法")] public static List app(params string[] sections) { List list = new List(); @@ -72,6 +147,7 @@ public static List app(params string[] sections) /// /// /// + [Obsolete("推荐使用 Git 方法")] public static string GetValue(string sectionsPath) { try @@ -83,5 +159,40 @@ public static string GetValue(string sectionsPath) return ""; } + #endregion + } +} + +namespace Microsoft.Extensions.Configuration +{ + /// + /// (配置) 拓展 + /// + public static class IConfigurationExtensions + { + /// + /// 判断节点是否存在 + /// + /// 配置 + /// 节点路径 + /// 节点存在返回 true,否者 false + public static bool Exists(this IConfiguration configuration, params string[] sections) => configuration.GetSection(string.Join(':', sections)).Exists(); + + /// + /// 读取节点字符串 + /// + /// 配置 + /// 节点路径 + /// 和节点路径匹配的字符串 + public static string Get(this IConfiguration configuration, params string[] sections) => configuration[string.Join(':', sections)]; + + /// + /// 读取节点并转换成指定类型 + /// + /// 返回的类型 + /// 配置 + /// 节点路径 + /// 和节点路径匹配的T类型对象 + public static T Get(this IConfiguration configuration, params string[] sections) => configuration.GetSection(string.Join(':', sections)).Get(); } } diff --git a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs index 909e9a19..992dbf28 100644 --- a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs +++ b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs @@ -17,7 +17,7 @@ public static class ConfigurationBuilderExtensions /// /// /// apollo配置文件路径 如果写入appsettings.json中 则jsonPath传null即可 - public static void AddConfigurationApollo(this IConfigurationBuilder builder,string jsonPath) + public static void AddConfigurationApollo(this IConfigurationBuilder builder,string jsonPath= null) { if (!string.IsNullOrEmpty(jsonPath)) { diff --git a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs index 31ae3497..2cba680d 100644 --- a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs +++ b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs @@ -1,6 +1,4 @@ using Blog.Core.Common; -using Blog.Core.Common.Helper; -using Blog.Core.Common.LogHelper; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/Blog.Core.Gateway/CustomConfig/ApiGateWay.json b/Blog.Core.Gateway/CustomConfig/ApiGateWay.json new file mode 100644 index 00000000..3fdd4e3e --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/ApiGateWay.json @@ -0,0 +1,11 @@ +{ + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Audience.json b/Blog.Core.Gateway/CustomConfig/Audience.json new file mode 100644 index 00000000..da3b0b7b --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/BlackList.json b/Blog.Core.Gateway/CustomConfig/BlackList.json new file mode 100644 index 00000000..e467c015 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/BlackList.json @@ -0,0 +1,5 @@ +{ + "BlackList": [ + { "url": "/favicon.ico" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Influxdb.json b/Blog.Core.Gateway/CustomConfig/Influxdb.json new file mode 100644 index 00000000..18cc201e --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Influxdb.json @@ -0,0 +1,8 @@ +{ + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Nacos.json b/Blog.Core.Gateway/CustomConfig/Nacos.json new file mode 100644 index 00000000..ce2afaf0 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Nacos.json @@ -0,0 +1,31 @@ +{ + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/ocelot.Development.json b/Blog.Core.Gateway/CustomConfig/Ocelot.json similarity index 100% rename from Blog.Core.Gateway/ocelot.Development.json rename to Blog.Core.Gateway/CustomConfig/Ocelot.json diff --git a/Blog.Core.Gateway/CustomConfig/Startup.json b/Blog.Core.Gateway/CustomConfig/Startup.json new file mode 100644 index 00000000..9a2ad0f6 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Startup.json @@ -0,0 +1,9 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/WhiteList.json b/Blog.Core.Gateway/CustomConfig/WhiteList.json new file mode 100644 index 00000000..afd00316 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/WhiteList.json @@ -0,0 +1,8 @@ +{ + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/nacosConfig.json b/Blog.Core.Gateway/CustomConfig/nacosConfig.json new file mode 100644 index 00000000..26edf7a5 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/nacosConfig.json @@ -0,0 +1,19 @@ +{ + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json b/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json new file mode 100644 index 00000000..3fdd4e3e --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json @@ -0,0 +1,11 @@ +{ + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json new file mode 100644 index 00000000..da3b0b7b --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json b/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json new file mode 100644 index 00000000..e467c015 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json @@ -0,0 +1,5 @@ +{ + "BlackList": [ + { "url": "/favicon.ico" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json new file mode 100644 index 00000000..18cc201e --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json @@ -0,0 +1,8 @@ +{ + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json new file mode 100644 index 00000000..ce2afaf0 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json @@ -0,0 +1,31 @@ +{ + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json new file mode 100644 index 00000000..6af5171b --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json @@ -0,0 +1,59 @@ +{ + "Routes": [ + // blog-svc + { + "UpstreamPathTemplate": "/svc/blog/{url}", + "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ], + "LoadBalancerOptions": { + "Type": "RoundRobin" + }, + "DownstreamPathTemplate": "/svc/blog/{url}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 9291 + } + ], + "AddHeadersToRequest": { + "user-phone": "Claims[user-phone] > value", + "gw-sign": "Claims[gw-sign] > value" + }, + "UpstreamHeaderTransform": { + "custom-key": "blog.gateway" + }, + "DownstreamHeaderTransform": { + "trace-id": "Trace-Id" + }, + "AuthenticationOptions": { + "AuthenticationProviderKey": "GW" + }, + "DelegatingHandlers": [ + "CustomResultHandler" + ] + }, + // blog-svc-swagger + { + "UpstreamPathTemplate": "/swagger/apiswg/blog-svc/swagger.json", + "UpstreamHttpMethod": [ "GET" ], + "DownstreamPathTemplate": "/swagger/V2/swagger.json", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 9291 + } + ], + "LoadBalancer": "RoundRobin" + } + + ], + "GlobalConfiguration": { + "BaseUrl": "http://localhost:9000", + "ServiceDiscoveryProvider": { + "Host": "localhost", + "Port": 8500, + "Type": "Consul" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json new file mode 100644 index 00000000..9a2ad0f6 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json @@ -0,0 +1,9 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json b/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json new file mode 100644 index 00000000..afd00316 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json @@ -0,0 +1,8 @@ +{ + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json b/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json new file mode 100644 index 00000000..26edf7a5 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json @@ -0,0 +1,19 @@ +{ + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs b/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs index 6c7d048e..fafcc38f 100644 --- a/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs +++ b/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs @@ -35,7 +35,7 @@ public class CustomJwtTokenAuthMiddleware private readonly RequestDelegate _next; - public CustomJwtTokenAuthMiddleware(INacosNamingService serv, RequestDelegate next, IAuthenticationSchemeProvider schemes, Appsettings appset,ICaching cache) + public CustomJwtTokenAuthMiddleware(INacosNamingService serv, RequestDelegate next, IAuthenticationSchemeProvider schemes,ICaching cache) { NacosServClient = serv; _cache = cache; diff --git a/Blog.Core.Gateway/Program.cs b/Blog.Core.Gateway/Program.cs index 1ba46816..211dbac0 100644 --- a/Blog.Core.Gateway/Program.cs +++ b/Blog.Core.Gateway/Program.cs @@ -1,5 +1,5 @@ +using Blog.Core.Common; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; namespace Blog.Core.AdminMvc @@ -13,11 +13,7 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.AddJsonFile("ocelot.json", optional: true, reloadOnChange: true) - .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true); - }) + .ConfigureAppConfiguration(Appsettings.AddConfigureFiles) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup().UseUrls("http://*:9000"); diff --git a/Blog.Core.Gateway/Startup.cs b/Blog.Core.Gateway/Startup.cs index 23c5caa0..362aea5b 100644 --- a/Blog.Core.Gateway/Startup.cs +++ b/Blog.Core.Gateway/Startup.cs @@ -32,8 +32,6 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env) // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(new Appsettings(Configuration)); - services.AddAuthentication_JWTSetup(); services.AddAuthentication() diff --git a/Blog.Core.Gateway/appsettings.Development.json b/Blog.Core.Gateway/appsettings.Development.json index 8983e0fc..5747c9d4 100644 --- a/Blog.Core.Gateway/appsettings.Development.json +++ b/Blog.Core.Gateway/appsettings.Development.json @@ -5,5 +5,16 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } + }, + + // ԶϢ + "CustomConfigInfo": { + /* + ԶļĿ¼ + Ŀ¼ֳ֧Ŀ¼º;· + жͬ·ã潫Ḳǰ + ļ·дں + */ + "ConfigFileFolders": [ "DevelopmentCustomConfig" ] } } diff --git a/Blog.Core.Gateway/appsettings.Production.json b/Blog.Core.Gateway/appsettings.Production.json new file mode 100644 index 00000000..2d4915b5 --- /dev/null +++ b/Blog.Core.Gateway/appsettings.Production.json @@ -0,0 +1,12 @@ +{ + // ԶϢ + "CustomConfigInfo": { + /* + ԶļĿ¼ + Ŀ¼ֳ֧Ŀ¼º;· + жͬ·ã潫Ḳǰ + ļ·дں + */ + "ConfigFileFolders": [ "CustomConfig" ] + } +} diff --git a/Blog.Core.Gateway/appsettings.Staging.json b/Blog.Core.Gateway/appsettings.Staging.json new file mode 100644 index 00000000..2d4915b5 --- /dev/null +++ b/Blog.Core.Gateway/appsettings.Staging.json @@ -0,0 +1,12 @@ +{ + // ԶϢ + "CustomConfigInfo": { + /* + ԶļĿ¼ + Ŀ¼ֳ֧Ŀ¼º;· + жͬ·ã潫Ḳǰ + ļ·дں + */ + "ConfigFileFolders": [ "CustomConfig" ] + } +} diff --git a/Blog.Core.Gateway/appsettings.backup.json b/Blog.Core.Gateway/appsettings.backup.json new file mode 100644 index 00000000..2dcab917 --- /dev/null +++ b/Blog.Core.Gateway/appsettings.backup.json @@ -0,0 +1,104 @@ +//appsettings +{ + "Logging": { + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + } + }, + "AllowedHosts": "*", + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + }, + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + }, + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ], + "BlackList": [ + { "url": "/favicon.ico" } + ], + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + }, + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + }, + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + }, + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } + + + +} diff --git a/Blog.Core.Gateway/appsettings.json b/Blog.Core.Gateway/appsettings.json index 33b99ee8..40645ab1 100644 --- a/Blog.Core.Gateway/appsettings.json +++ b/Blog.Core.Gateway/appsettings.json @@ -14,90 +14,15 @@ } }, "AllowedHosts": "*", - "Startup": { - "Cors": { - "PolicyName": "CorsIpAccess", - "EnableAllIPs": false, - "IPs": "http://127.0.0.1:2364,http://localhost:2364" - } - }, - "Audience": { - "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", - "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", - "Issuer": "Blog.Core", - "Audience": "wr" - }, - "WhiteList": [ - { "url": "/" }, - { "url": "/illagal/****" }, - { "url": "/api3/****" }, - { "url": "/baseapi/swagger.json" } - ], - "BlackList": [ - { "url": "/favicon.ico" } - ], - "ApiGateWay": { - "OcelotConfig": "OcelotConfig.json", - "OcelotConfigGroup": "DEFAULT_GROUP", - "AppConfig": "****.****.Gateway.json", - "AppConfigGroup": "DEFAULT_GROUP", - "PermissionServName": "****.****.Api", - "PermissionServGroup": "DEFAULT_GROUP", - "PermissionServUrl": "/api/Permission/GetPermissionlist" - }, - "Influxdb": { - "Endpoint": "http://*******:9328", - "uid": "root", - "pwd": "*****", - "dbname": "mndata" - }, - "nacos": { - "ServerAddresses": [ "http://******:8848/" ], - "ServiceName": "*****.****.Gateway", - "DefaultTimeOut": 15000, - "Namespace": "****", - "ListenInterval": 1000, - "GroupName": "DEFAULT_GROUP", - "ClusterName": "DEFAULT", - "Ip": "", - "PreferredNetworks": "", - "Port": 8090, - "Weight": 100, - "RegisterEnabled": true, - "InstanceEnabled": true, - "Ephemeral": true, - "Secure": false, - "AccessKey": "", - "SecretKey": "", - "UserName": "****", - "Password": "*****", - "NamingUseRpc": true, - "NamingLoadCacheAtStart": "", - "LBStrategy": "WeightRandom", - "Metadata": { - "aa": "bb", - "cc": "dd", - "endpoint33": "******:8090" - } - }, - "nacosConfig": { - "ServiceName": "*****.*****.Gateway", - "Optional": false, - "DataId": "options1", - "Tenant": "******", - "Group": "DEFAULT_GROUP", - "Namespace": "*****", - "ServerAddresses": [ "http://******:8848/" ], - "UserName": "****", - "Password": "*****", - "AccessKey": "", - "SecretKey": "", - "EndPoint": "", - "ConfigUseRpc": true, - "ConfigFilterAssemblies": [ "apigateway" ], - "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" - } - - + // ԶϢ + "CustomConfigInfo": { + /* + ԶļĿ¼ + Ŀ¼ֳ֧Ŀ¼º;· + жͬ·ã潫Ḳǰ + ļ·дں + */ + "ConfigFileFolders": [ "CustomConfig" ] + } } diff --git a/Blog.Core.Gateway/ocelot.Production.json b/Blog.Core.Gateway/ocelot.Production.json deleted file mode 100644 index 0db3279e..00000000 --- a/Blog.Core.Gateway/ocelot.Production.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/Blog.Core.Gateway/ocelot.Staging.json b/Blog.Core.Gateway/ocelot.Staging.json deleted file mode 100644 index 0db3279e..00000000 --- a/Blog.Core.Gateway/ocelot.Staging.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/Blog.Core.Gateway/ocelot.json b/Blog.Core.Gateway/ocelot.json deleted file mode 100644 index 29091fa5..00000000 --- a/Blog.Core.Gateway/ocelot.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/Blog.Core.Tests/DependencyInjection/DI_Test.cs b/Blog.Core.Tests/DependencyInjection/DI_Test.cs index 23e46bf6..2e3512e6 100644 --- a/Blog.Core.Tests/DependencyInjection/DI_Test.cs +++ b/Blog.Core.Tests/DependencyInjection/DI_Test.cs @@ -52,11 +52,11 @@ public static MutiDBOperate GetMainConnectionDb() public IContainer DICollections() { var basePath = AppContext.BaseDirectory; + Appsettings.Init(basePath); IServiceCollection services = new ServiceCollection(); services.AddAutoMapper(typeof(Startup)); - services.AddSingleton(new Appsettings(basePath)); services.AddSingleton(new LogLock(basePath)); services.AddScoped(); services.AddScoped(); From dd2bc7486d4c9f4ecdf3c95c50dcb51e3153f3c4 Mon Sep 17 00:00:00 2001 From: Linlccc <1610450962@qq.com> Date: Sun, 6 Mar 2022 18:27:30 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E7=BC=96=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Blog.Core.Api/CustomConfig/Apollo.json | 6 +++--- Blog.Core.Common/Helper/Appsettings.cs | 10 ++++------ Blog.Core.Gateway/appsettings.backup.json | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Blog.Core.Api/CustomConfig/Apollo.json b/Blog.Core.Api/CustomConfig/Apollo.json index 27e01459..0ca96f5b 100644 --- a/Blog.Core.Api/CustomConfig/Apollo.json +++ b/Blog.Core.Api/CustomConfig/Apollo.json @@ -1,5 +1,5 @@ -{ - //apollo +{ + //apollo 配置 "Apollo": { "Enable": false, "Config": { @@ -8,7 +8,7 @@ "MetaServer": "http://localhost:8080/", "ConfigServer": [ "http://localhost:8080/" ] }, - "Namespaces": [ //NamespacesݸʽProperties,Xml,Json,Yml,Yaml,Txt + "Namespaces": [ //Namespaces的数据格式Properties,Xml,Json,Yml,Yaml,Txt { "Name": "test", "Format": "json" diff --git a/Blog.Core.Common/Helper/Appsettings.cs b/Blog.Core.Common/Helper/Appsettings.cs index df5ce7a9..e2455048 100644 --- a/Blog.Core.Common/Helper/Appsettings.cs +++ b/Blog.Core.Common/Helper/Appsettings.cs @@ -55,11 +55,10 @@ public static void AddConfigureFiles(HostBuilderContext hostBuilder, IConfigurat customConfigFolder.ToList().ForEach(folder => jsonFiles.AddRange(Directory.GetFiles(folder, "*.json", SearchOption.TopDirectoryOnly))); // 将配置文件添加到配置中 - jsonFiles.ForEach(jsonFile => builder.AddJsonFile(jsonFile, true, true)); + jsonFiles.ForEach(jsonFile => builder.AddJsonFile(jsonFile, true, false)); Configuration = builder.Build(); - /// /// 获取默认配置文件 /// @@ -67,7 +66,6 @@ public static void AddConfigureFiles(HostBuilderContext hostBuilder, IConfigurat static List GetDefaultConfigFiles() { List configFiles = new() { "appsettings.json" }; - ; string ASPNETCORE_ENVIRONMENT = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (ASPNETCORE_ENVIRONMENT?.Length > 0) configFiles.Add($"appsettings.{ASPNETCORE_ENVIRONMENT}.json"); return configFiles; @@ -110,7 +108,7 @@ static List GetDefaultConfigFiles() /// /// 节点配置 /// - [Obsolete("推荐使用 Git 方法")] + [Obsolete("推荐使用 Get 方法")] public static string app(params string[] sections) { try @@ -132,7 +130,7 @@ public static string app(params string[] sections) /// /// /// - [Obsolete("推荐使用 Git 方法")] + [Obsolete("推荐使用 Get 方法")] public static List app(params string[] sections) { List list = new List(); @@ -147,7 +145,7 @@ public static List app(params string[] sections) /// /// /// - [Obsolete("推荐使用 Git 方法")] + [Obsolete("推荐使用 Get 方法")] public static string GetValue(string sectionsPath) { try diff --git a/Blog.Core.Gateway/appsettings.backup.json b/Blog.Core.Gateway/appsettings.backup.json index 2dcab917..c986b56c 100644 --- a/Blog.Core.Gateway/appsettings.backup.json +++ b/Blog.Core.Gateway/appsettings.backup.json @@ -1,4 +1,4 @@ -//appsettings +//appsettings 备份 { "Logging": { "IncludeScopes": false, From bb569aea823fcdb657ab62a934cc6a0cc0886c0d Mon Sep 17 00:00:00 2001 From: Linlccc <1610450962@qq.com> Date: Thu, 5 May 2022 15:12:39 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=90=88=E5=B9=B6anjoy8-?= =?UTF-8?q?master=E5=90=8E=E5=86=B2=E7=AA=81=E5=BC=95=E5=8F=91=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Blog.Core.Api/CustomConfig/Middleware.json | 3 +++ .../DevelopmentCustomConfig/Middleware.json | 3 +++ Blog.Core.Api/Program.cs | 9 ++------ Blog.Core.Api/appsettings.backup.json | 22 +++++-------------- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Blog.Core.Api/CustomConfig/Middleware.json b/Blog.Core.Api/CustomConfig/Middleware.json index 710da3c3..d971fc43 100644 --- a/Blog.Core.Api/CustomConfig/Middleware.json +++ b/Blog.Core.Api/CustomConfig/Middleware.json @@ -13,6 +13,9 @@ "SignalR": { "Enabled": false }, + "SignalRSendLog": { + "Enabled": false + }, "QuartzNetJob": { "Enabled": true }, diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json index 710da3c3..d971fc43 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json @@ -13,6 +13,9 @@ "SignalR": { "Enabled": false }, + "SignalRSendLog": { + "Enabled": false + }, "QuartzNetJob": { "Enabled": true }, diff --git a/Blog.Core.Api/Program.cs b/Blog.Core.Api/Program.cs index 285025c6..89b0ae00 100644 --- a/Blog.Core.Api/Program.cs +++ b/Blog.Core.Api/Program.cs @@ -42,16 +42,11 @@ builder.SetMinimumLevel(LogLevel.Error); builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config")); }) -.ConfigureAppConfiguration((hostingContext, config) => -{ - config.Sources.Clear(); - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); - config.AddConfigurationApollo("appsettings.apollo.json"); -}); +.ConfigureAppConfiguration(Appsettings.AddConfigureFiles) +.ConfigureAppConfiguration(config=> config.AddConfigurationApollo()); // 2、配置服务 -builder.Services.AddSingleton(new Appsettings(builder.Configuration)); builder.Services.AddSingleton(new LogLock(builder.Environment.ContentRootPath)); builder.Services.AddUiFilesZipSetup(builder.Environment); diff --git a/Blog.Core.Api/appsettings.backup.json b/Blog.Core.Api/appsettings.backup.json index 4603a80d..b93b31ca 100644 --- a/Blog.Core.Api/appsettings.backup.json +++ b/Blog.Core.Api/appsettings.backup.json @@ -1,4 +1,3 @@ -//之前的appsettings 备份 { "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 "Logging": { @@ -6,13 +5,14 @@ "Default": "Information", //加入Default否则log4net本地写入不了日志 "Blog.Core.AuthHelper.ApiResponseHandler": "Error" }, - "IncludeScopes": false, "Debug": { + "IncludeScopes": false, "LogLevel": { "Default": "Warning" } }, "Console": { + "IncludeScopes": false, "LogLevel": { "Default": "Warning", "Microsoft.Hosting.Lifetime": "Debug" @@ -23,19 +23,6 @@ } }, "AllowedHosts": "*", - - // 自定义配置信息 - "CustomConfigInfo": { - /* - 自定义配置文件目录 - 目录支持程序根目录下和绝对路径 - 如果有多个相同路径的配置,后面将会覆盖前面的内容 - 建议测试类的配置文件夹路径写在后面 - */ - "ConfigFileFolders": [ "CustomConfig" ] - }, - - "Redis": { "ConnectionString": "127.0.0.1:6319,password=admin" }, @@ -219,6 +206,9 @@ "SignalR": { "Enabled": false }, + "SignalRSendLog": { + "Enabled": false + }, "QuartzNetJob": { "Enabled": true }, @@ -302,4 +292,4 @@ } ] } -} +} \ No newline at end of file From bd9c0486ada6a2aa8e07bf47bba4ec94a3758680 Mon Sep 17 00:00:00 2001 From: Linlccc <1610450962@qq.com> Date: Thu, 5 May 2022 16:10:24 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=90=88=E5=B9=B6json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Blog.Core.Api/Blog.Core.Api.csproj | 5 +++++ Blog.Core.Api/appsettings.Development.json | 13 +++++-------- Blog.Core.Api/appsettings.json | 11 ++++------- Blog.Core.Common/Helper/Appsettings.cs | 19 +------------------ .../Apollo/ConfigurationBuilderExtensions.cs | 4 +++- 5 files changed, 18 insertions(+), 34 deletions(-) diff --git a/Blog.Core.Api/Blog.Core.Api.csproj b/Blog.Core.Api/Blog.Core.Api.csproj index 74f1f1b1..1f3b4c5b 100644 --- a/Blog.Core.Api/Blog.Core.Api.csproj +++ b/Blog.Core.Api/Blog.Core.Api.csproj @@ -11,6 +11,10 @@ true + + true + + ..\Blog.Core.Api\Blog.Core.xml 1701;1702;1591 @@ -48,6 +52,7 @@ + diff --git a/Blog.Core.Api/appsettings.Development.json b/Blog.Core.Api/appsettings.Development.json index 0bd28162..4002901e 100644 --- a/Blog.Core.Api/appsettings.Development.json +++ b/Blog.Core.Api/appsettings.Development.json @@ -22,15 +22,12 @@ } }, "AllowedHosts": "*", - + // 自定义配置信息 "CustomConfigInfo": { - /* - 自定义配置文件目录 - 目录支持程序根目录下和绝对路径 - 如果有多个相同路径的配置,后面将会覆盖前面的内容 - 建议测试类的配置文件夹路径写在后面 - */ - "ConfigFileFolders": [ "DevelopmentCustomConfig" ] + // 子文件目录集合 + "ConfigFileFolders": [ "DevelopmentCustomConfig" ], + // 要排除的文件名集合 + "ExcludeSubFiles": [] } } diff --git a/Blog.Core.Api/appsettings.json b/Blog.Core.Api/appsettings.json index 3ad1a4fa..862dde75 100644 --- a/Blog.Core.Api/appsettings.json +++ b/Blog.Core.Api/appsettings.json @@ -26,12 +26,9 @@ // 自定义配置信息 "CustomConfigInfo": { - /* - 自定义配置文件目录 - 目录支持程序根目录下和绝对路径 - 如果有多个相同路径的配置,后面将会覆盖前面的内容 - 建议测试类的配置文件夹路径写在后面 - */ - "ConfigFileFolders": ["CustomConfig"] + // 子文件目录集合 + "ConfigFileFolders": [ "CustomConfig" ], + // 要排除的文件名集合 + "ExcludeSubFiles": [ ] } } diff --git a/Blog.Core.Common/Helper/Appsettings.cs b/Blog.Core.Common/Helper/Appsettings.cs index e2455048..c91374a8 100644 --- a/Blog.Core.Common/Helper/Appsettings.cs +++ b/Blog.Core.Common/Helper/Appsettings.cs @@ -39,24 +39,7 @@ public static void AddConfigureFiles(HostBuilderContext hostBuilder, IConfigurat { //清除原配置,添加默认配置 builder.Sources.Clear(); - GetDefaultConfigFiles().ForEach(file =>builder.AddJsonFile(file)); - - IConfigurationRoot configuration = builder.Build(); - // 获取自定义配置文件夹 && 文件夹存在 - IEnumerable customConfigFolder = configuration.Get>("CustomConfigInfo", "ConfigFileFolders")?.Where(folderPath => Directory.Exists(folderPath)); - if(customConfigFolder is null || !customConfigFolder.Any()) - { - Configuration = builder.Build(); - return; - } - - // 获取所有配置文件 - List jsonFiles = new(); - customConfigFolder.ToList().ForEach(folder => jsonFiles.AddRange(Directory.GetFiles(folder, "*.json", SearchOption.TopDirectoryOnly))); - - // 将配置文件添加到配置中 - jsonFiles.ForEach(jsonFile => builder.AddJsonFile(jsonFile, true, false)); - + GetDefaultConfigFiles().ForEach(file => builder.AddJsonFile(Path.Combine(AppContext.BaseDirectory, file))); Configuration = builder.Build(); /// diff --git a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs index 992dbf28..2050a04d 100644 --- a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs +++ b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs @@ -7,6 +7,7 @@ using Com.Ctrip.Framework.Apollo.Logging; using Microsoft.Extensions.Primitives; using System.Reflection; +using Blog.Core.Common; namespace Blog.Core.Extensions.Apollo { @@ -36,8 +37,9 @@ public static void AddConfigurationApollo(this IConfigurationBuilder builder,str { apolloBuilder.AddNamespace(item.Name, MatchConfigFileFormat(item.Format)); } + Appsettings.Configuration = builder.Build(); //监听apollo配置 - Monitor(builder.Build()); + Monitor((IConfigurationRoot)Appsettings.Configuration); } } From 252f8c03fcae72a3359b6635061c2606e91988d3 Mon Sep 17 00:00:00 2001 From: anjoy8 <3143422472@qq.com> Date: Sun, 26 Feb 2023 10:32:47 +0800 Subject: [PATCH 5/8] feat:change appSetting --- Blog.Core.Api/Program.cs | 2 +- Blog.Core.Common/Helper/Appsettings.cs | 2 +- Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs | 4 ++-- Blog.Core.Gateway/Program.cs | 2 +- Blog.Core.Tests/DependencyInjection/DI_Test.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Blog.Core.Api/Program.cs b/Blog.Core.Api/Program.cs index c3c4b589..f0ec67bf 100644 --- a/Blog.Core.Api/Program.cs +++ b/Blog.Core.Api/Program.cs @@ -40,7 +40,7 @@ builder.SetMinimumLevel(LogLevel.Error); builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config")); }) -.ConfigureAppConfiguration(Appsettings.AddConfigureFiles) +.ConfigureAppConfiguration(AppSettings.AddConfigureFiles) .ConfigureAppConfiguration(config=> config.AddConfigurationApollo()); // 2、配置服务 diff --git a/Blog.Core.Common/Helper/Appsettings.cs b/Blog.Core.Common/Helper/Appsettings.cs index c91374a8..3ab4e663 100644 --- a/Blog.Core.Common/Helper/Appsettings.cs +++ b/Blog.Core.Common/Helper/Appsettings.cs @@ -9,7 +9,7 @@ namespace Blog.Core.Common { - public static class Appsettings + public static class AppSettings { /// /// 配置 diff --git a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs index 2050a04d..6e832f36 100644 --- a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs +++ b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs @@ -37,9 +37,9 @@ public static void AddConfigurationApollo(this IConfigurationBuilder builder,str { apolloBuilder.AddNamespace(item.Name, MatchConfigFileFormat(item.Format)); } - Appsettings.Configuration = builder.Build(); + AppSettings.Configuration = builder.Build(); //监听apollo配置 - Monitor((IConfigurationRoot)Appsettings.Configuration); + Monitor((IConfigurationRoot)AppSettings.Configuration); } } diff --git a/Blog.Core.Gateway/Program.cs b/Blog.Core.Gateway/Program.cs index 211dbac0..caf9a65b 100644 --- a/Blog.Core.Gateway/Program.cs +++ b/Blog.Core.Gateway/Program.cs @@ -13,7 +13,7 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(Appsettings.AddConfigureFiles) + .ConfigureAppConfiguration(AppSettings.AddConfigureFiles) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup().UseUrls("http://*:9000"); diff --git a/Blog.Core.Tests/DependencyInjection/DI_Test.cs b/Blog.Core.Tests/DependencyInjection/DI_Test.cs index db3f2d54..a38cc2d5 100644 --- a/Blog.Core.Tests/DependencyInjection/DI_Test.cs +++ b/Blog.Core.Tests/DependencyInjection/DI_Test.cs @@ -54,7 +54,7 @@ public static MutiDBOperate GetMainConnectionDb() public IContainer DICollections() { var basePath = AppContext.BaseDirectory; - Appsettings.Init(basePath); + AppSettings.Init(basePath); IServiceCollection services = new ServiceCollection(); services.AddAutoMapper(typeof(Startup)); From ba5578187c3436803273dd1080f3d2ef9e8a8222 Mon Sep 17 00:00:00 2001 From: anjoy8 <3143422472@qq.com> Date: Sun, 26 Feb 2023 10:54:30 +0800 Subject: [PATCH 6/8] feat: update custom config json --- Blog.Core.Api/CustomConfig/AppSettings.json | 20 +++++--- Blog.Core.Api/CustomConfig/Db.json | 2 +- Blog.Core.Api/CustomConfig/Middleware.json | 22 ++++++++- Blog.Core.Api/CustomConfig/Startup.json | 9 +++- Blog.Core.Api/appsettings.backup.json | 55 ++++++++++++++++----- 5 files changed, 85 insertions(+), 23 deletions(-) diff --git a/Blog.Core.Api/CustomConfig/AppSettings.json b/Blog.Core.Api/CustomConfig/AppSettings.json index 92043539..a9f746b1 100644 --- a/Blog.Core.Api/CustomConfig/AppSettings.json +++ b/Blog.Core.Api/CustomConfig/AppSettings.json @@ -7,23 +7,29 @@ "Enabled": true }, "LogAOP": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "TranAOP": { - "Enabled": false + "Enabled": true }, "SqlAOP": { "Enabled": true, - "OutToLogFile": { + "LogToFile": { + "Enabled": false + }, + "LogToDB": { "Enabled": false }, - "OutToConsole": { + "LogToConsole": { "Enabled": true } }, - "LogToDb": { - "Enabled": true - }, "Date": "2018-08-28", "SeedDBEnabled": true, //只生成表结构 "SeedDBDataEnabled": true, //生成表,并初始化数据 diff --git a/Blog.Core.Api/CustomConfig/Db.json b/Blog.Core.Api/CustomConfig/Db.json index ad17697c..2c2935b5 100644 --- a/Blog.Core.Api/CustomConfig/Db.json +++ b/Blog.Core.Api/CustomConfig/Db.json @@ -53,7 +53,7 @@ "DBType": 0, "Enabled": true, "HitRate": 20, - "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" }, { "ConnId": "WMBLOG_ORACLE", diff --git a/Blog.Core.Api/CustomConfig/Middleware.json b/Blog.Core.Api/CustomConfig/Middleware.json index d971fc43..b211f54d 100644 --- a/Blog.Core.Api/CustomConfig/Middleware.json +++ b/Blog.Core.Api/CustomConfig/Middleware.json @@ -1,13 +1,31 @@ { "Middleware": { "RequestResponseLog": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "IPLog": { - "Enabled": true + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "RecordAccessLogs": { "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," }, "SignalR": { diff --git a/Blog.Core.Api/CustomConfig/Startup.json b/Blog.Core.Api/CustomConfig/Startup.json index accd3ce1..3f1c3e2f 100644 --- a/Blog.Core.Api/CustomConfig/Startup.json +++ b/Blog.Core.Api/CustomConfig/Startup.json @@ -1,11 +1,12 @@ { "Startup": { + "Domain": "http://localhost:9291", "Cors": { "PolicyName": "CorsIpAccess", //策略名称 "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364" + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" }, "AppConfigAlert": { "Enabled": true @@ -16,6 +17,12 @@ "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 "ApiName": "blog.core.api" // 资源服务器 }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, "RedisMq": { "Enabled": false //redis 消息队列 }, diff --git a/Blog.Core.Api/appsettings.backup.json b/Blog.Core.Api/appsettings.backup.json index b93b31ca..ea678174 100644 --- a/Blog.Core.Api/appsettings.backup.json +++ b/Blog.Core.Api/appsettings.backup.json @@ -52,23 +52,29 @@ "Enabled": true }, "LogAOP": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "TranAOP": { - "Enabled": false + "Enabled": true }, "SqlAOP": { "Enabled": true, - "OutToLogFile": { + "LogToFile": { "Enabled": false }, - "OutToConsole": { + "LogToDB": { + "Enabled": false + }, + "LogToConsole": { "Enabled": true } }, - "LogToDb": { - "Enabled": true - }, "Date": "2018-08-28", "SeedDBEnabled": true, //只生成表结构 "SeedDBDataEnabled": true, //生成表,并初始化数据 @@ -131,7 +137,7 @@ "DBType": 0, "Enabled": true, "HitRate": 20, - "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" }, { "ConnId": "WMBLOG_ORACLE", @@ -166,12 +172,13 @@ "Database": "BlogCoreDb" }, "Startup": { + "Domain": "http://localhost:9291", "Cors": { "PolicyName": "CorsIpAccess", //策略名称 "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364" + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" }, "AppConfigAlert": { "Enabled": true @@ -182,6 +189,12 @@ "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 "ApiName": "blog.core.api" // 资源服务器 }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, "RedisMq": { "Enabled": false //redis 消息队列 }, @@ -194,13 +207,31 @@ }, "Middleware": { "RequestResponseLog": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "IPLog": { - "Enabled": true + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "RecordAccessLogs": { "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," }, "SignalR": { @@ -292,4 +323,4 @@ } ] } -} \ No newline at end of file +} From ca011b4a505660533fd98bceaa7f989d23fcb856 Mon Sep 17 00:00:00 2001 From: anjoy8 <3143422472@qq.com> Date: Sun, 26 Feb 2023 11:02:44 +0800 Subject: [PATCH 7/8] =?UTF-8?q?feat=EF=BC=9Aupdate=20development=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentCustomConfig/Apollo.json | 6 ++--- .../DevelopmentCustomConfig/AppSettings.json | 20 +++++++++++------ Blog.Core.Api/DevelopmentCustomConfig/Db.json | 2 +- .../DevelopmentCustomConfig/Middleware.json | 22 +++++++++++++++++-- .../DevelopmentCustomConfig/Startup.json | 9 +++++++- .../appsettings.Development.json | 9 ++------ 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json index 27e01459..0ca96f5b 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json @@ -1,5 +1,5 @@ -{ - //apollo +{ + //apollo 配置 "Apollo": { "Enable": false, "Config": { @@ -8,7 +8,7 @@ "MetaServer": "http://localhost:8080/", "ConfigServer": [ "http://localhost:8080/" ] }, - "Namespaces": [ //NamespacesݸʽProperties,Xml,Json,Yml,Yaml,Txt + "Namespaces": [ //Namespaces的数据格式Properties,Xml,Json,Yml,Yaml,Txt { "Name": "test", "Format": "json" diff --git a/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json index 92043539..a9f746b1 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json @@ -7,23 +7,29 @@ "Enabled": true }, "LogAOP": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "TranAOP": { - "Enabled": false + "Enabled": true }, "SqlAOP": { "Enabled": true, - "OutToLogFile": { + "LogToFile": { + "Enabled": false + }, + "LogToDB": { "Enabled": false }, - "OutToConsole": { + "LogToConsole": { "Enabled": true } }, - "LogToDb": { - "Enabled": true - }, "Date": "2018-08-28", "SeedDBEnabled": true, //只生成表结构 "SeedDBDataEnabled": true, //生成表,并初始化数据 diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Db.json b/Blog.Core.Api/DevelopmentCustomConfig/Db.json index ad17697c..2c2935b5 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/Db.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/Db.json @@ -53,7 +53,7 @@ "DBType": 0, "Enabled": true, "HitRate": 20, - "Connection": "server=.;Database=blogcore001;Uid=root;Pwd=123456;Port=3096;Allow User Variables=True;" + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" }, { "ConnId": "WMBLOG_ORACLE", diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json index d971fc43..b211f54d 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json @@ -1,13 +1,31 @@ { "Middleware": { "RequestResponseLog": { - "Enabled": false + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "IPLog": { - "Enabled": true + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } }, "RecordAccessLogs": { "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," }, "SignalR": { diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Startup.json b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json index accd3ce1..3f1c3e2f 100644 --- a/Blog.Core.Api/DevelopmentCustomConfig/Startup.json +++ b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json @@ -1,11 +1,12 @@ { "Startup": { + "Domain": "http://localhost:9291", "Cors": { "PolicyName": "CorsIpAccess", //策略名称 "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364" + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" }, "AppConfigAlert": { "Enabled": true @@ -16,6 +17,12 @@ "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 "ApiName": "blog.core.api" // 资源服务器 }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, "RedisMq": { "Enabled": false //redis 消息队列 }, diff --git a/Blog.Core.Gateway/appsettings.Development.json b/Blog.Core.Gateway/appsettings.Development.json index 5747c9d4..a25d5e7f 100644 --- a/Blog.Core.Gateway/appsettings.Development.json +++ b/Blog.Core.Gateway/appsettings.Development.json @@ -7,14 +7,9 @@ } }, - // ԶϢ + // 自定义配置信息 "CustomConfigInfo": { - /* - ԶļĿ¼ - Ŀ¼ֳ֧Ŀ¼º;· - жͬ·ã潫Ḳǰ - ļ·дں - */ + // 子文件目录集合 "ConfigFileFolders": [ "DevelopmentCustomConfig" ] } } From 3f77aed9083a7e42d7a65c188bb0ddcd21d53459 Mon Sep 17 00:00:00 2001 From: anjoy8 <3143422472@qq.com> Date: Sun, 26 Feb 2023 11:13:23 +0800 Subject: [PATCH 8/8] feat: sync gateway appsetings json --- Blog.Core.Gateway/appsettings.Development.json | 2 +- Blog.Core.Gateway/appsettings.Production.json | 12 ++++++------ Blog.Core.Gateway/appsettings.Staging.json | 12 ++++++------ Blog.Core.Gateway/appsettings.json | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Blog.Core.Gateway/appsettings.Development.json b/Blog.Core.Gateway/appsettings.Development.json index a25d5e7f..c242ca5b 100644 --- a/Blog.Core.Gateway/appsettings.Development.json +++ b/Blog.Core.Gateway/appsettings.Development.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "LogLevel": { "Default": "Information", diff --git a/Blog.Core.Gateway/appsettings.Production.json b/Blog.Core.Gateway/appsettings.Production.json index 2d4915b5..54fd3318 100644 --- a/Blog.Core.Gateway/appsettings.Production.json +++ b/Blog.Core.Gateway/appsettings.Production.json @@ -1,11 +1,11 @@ -{ - // ԶϢ +{ + // 自定义配置信息 "CustomConfigInfo": { /* - ԶļĿ¼ - Ŀ¼ֳ֧Ŀ¼º;· - жͬ·ã潫Ḳǰ - ļ·дں + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 */ "ConfigFileFolders": [ "CustomConfig" ] } diff --git a/Blog.Core.Gateway/appsettings.Staging.json b/Blog.Core.Gateway/appsettings.Staging.json index 2d4915b5..54fd3318 100644 --- a/Blog.Core.Gateway/appsettings.Staging.json +++ b/Blog.Core.Gateway/appsettings.Staging.json @@ -1,11 +1,11 @@ -{ - // ԶϢ +{ + // 自定义配置信息 "CustomConfigInfo": { /* - ԶļĿ¼ - Ŀ¼ֳ֧Ŀ¼º;· - жͬ·ã潫Ḳǰ - ļ·дں + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 */ "ConfigFileFolders": [ "CustomConfig" ] } diff --git a/Blog.Core.Gateway/appsettings.json b/Blog.Core.Gateway/appsettings.json index 40645ab1..e63d2990 100644 --- a/Blog.Core.Gateway/appsettings.json +++ b/Blog.Core.Gateway/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "IncludeScopes": false, "Debug": { @@ -15,13 +15,13 @@ }, "AllowedHosts": "*", - // ԶϢ + // 自定义配置信息 "CustomConfigInfo": { /* - ԶļĿ¼ - Ŀ¼ֳ֧Ŀ¼º;· - жͬ·ã潫Ḳǰ - ļ·дں + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 */ "ConfigFileFolders": [ "CustomConfig" ] }