parent
6c43874569
commit
d7a1e13cee
38 changed files with 4010 additions and 112 deletions
@ -0,0 +1,17 @@ |
||||
using AutoMapper; |
||||
|
||||
namespace ThirdPartyServices.API.Infrastructure |
||||
{ |
||||
/// <summary> |
||||
/// 配置AutoMapper |
||||
/// </summary> |
||||
public class AutoMapperProfile : Profile |
||||
{ |
||||
/// <summary> |
||||
/// 构造函数 |
||||
/// </summary> |
||||
public AutoMapperProfile() |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
autoReload="true" |
||||
throwExceptions="false" |
||||
internalLogLevel="Warn" internalLogFile="nlog-internal.log"> |
||||
|
||||
<!-- optional, add some variables |
||||
https://github.com/nlog/NLog/wiki/Configuration-file#variables |
||||
--> |
||||
<extensions> |
||||
<add assembly="NLog.Web.AspNetCore"/> |
||||
</extensions> |
||||
<!--<variable name="myvar" value="myvalue"/>--> |
||||
<variable name="year" value="${date:format=yyyy}"/> |
||||
<variable name="year_month" value="${date:format=yyyy-MM}"/> |
||||
<!-- |
||||
See https://github.com/nlog/nlog/wiki/Configuration-file |
||||
for information on customizing logging rules and outputs. |
||||
--> |
||||
<targets async="true"> |
||||
|
||||
<!-- |
||||
add your targets here |
||||
See https://github.com/nlog/NLog/wiki/Targets for possible targets. |
||||
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. |
||||
--> |
||||
|
||||
<!-- |
||||
Write events to a file with the date in the filename. |
||||
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" |
||||
layout="${longdate} ${uppercase:${level}} ${message}" /> |
||||
--> |
||||
<target xsi:type="AsyncWrapper" name="MyLogger"> |
||||
<target xsi:type="File" |
||||
layout="${longdate},${uppercase:${level}},${message}" |
||||
fileName="${basedir}/Log/${level}/${year}/${year_month}/${shortdate}.log" encoding="utf-8" /> |
||||
</target> |
||||
|
||||
<target xsi:type="Null" name="blackhole" /> |
||||
</targets> |
||||
|
||||
|
||||
|
||||
<rules> |
||||
<!-- add your logging rules here --> |
||||
|
||||
<!-- |
||||
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" |
||||
<logger name="*" minlevel="Debug" writeTo="f" /> |
||||
--> |
||||
<!--跳过Microsoft的系统日志--> |
||||
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" /> |
||||
<logger name="*" minlevel="Debug" writeTo="MyLogger" final="true"/> |
||||
<logger name="Microsoft.*" minlevel="Warn" writeTo="MyLogger" final="true"/> |
||||
</rules> |
||||
</nlog> |
||||
@ -1,27 +1,128 @@ |
||||
using Autofac; |
||||
using Autofac.Extensions.DependencyInjection; |
||||
using Common.Shared.Application.Core; |
||||
using Microsoft.OpenApi.Models; |
||||
using NLog; |
||||
using NLog.Extensions.Logging; |
||||
using NLog.Web; |
||||
using System.Reflection; |
||||
using ThirdPartyServices.API.Infrastructure; |
||||
|
||||
namespace ThirdPartyServices.API |
||||
{ |
||||
public class Program |
||||
{ |
||||
public static void Main(string[] args) |
||||
{ |
||||
var builder = WebApplication.CreateBuilder(args); |
||||
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); |
||||
logger.Debug("init main"); |
||||
try |
||||
{ |
||||
var builder = WebApplication.CreateBuilder(args); |
||||
|
||||
builder.Services.AddHttpContextAccessor(); |
||||
builder.Services.AddHttpClient(); |
||||
builder.Services.AddControllers(); |
||||
builder.Services.AddSingleton(builder.Configuration); |
||||
|
||||
#region Cors |
||||
|
||||
var isconfig = builder.Configuration.GetSection("IdentityClientConfig").Get<CorsWithOrigins>(); |
||||
builder.Services.AddCors(options => |
||||
{ |
||||
options.AddPolicy("_myAllowSpecificOrigins", |
||||
builder => |
||||
{ |
||||
builder |
||||
//.WithOrigins(isconfig.CorsOrigins) //被允许的来源,多个使用逗号分隔 |
||||
.AllowAnyOrigin() //允许所有源访问本API(开发环境设置) |
||||
.AllowAnyHeader() |
||||
.AllowAnyMethod() |
||||
.AllowCredentials() |
||||
.SetIsOriginAllowed((h) => true);//为Signalr新添加的配置 |
||||
}); |
||||
}); |
||||
|
||||
#endregion Cors |
||||
|
||||
#region SwaggerUI |
||||
|
||||
builder.Services.AddEndpointsApiExplorer(); |
||||
builder.Services.AddSwaggerGen(c => |
||||
{ |
||||
c.SwaggerDoc("v1.0", new OpenApiInfo |
||||
{ |
||||
Version = "v1.0", |
||||
Title = "WeiCloud.IoT",//左侧大标题名称 |
||||
Description = "安消一体化平台", |
||||
Contact = new OpenApiContact |
||||
{ |
||||
Name = "hi7t", |
||||
Email = "", |
||||
Url = null |
||||
} |
||||
}); |
||||
//c.OperationFilter<AddProjectHeaderParameter>(); |
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; |
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); |
||||
c.IncludeXmlComments(xmlPath, true); |
||||
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); |
||||
}); |
||||
|
||||
#endregion SwaggerUI |
||||
|
||||
builder.Services.AddLogging(m => { m.AddNLog(); }); |
||||
|
||||
#region Autofac |
||||
|
||||
// Add services to the container. |
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()) |
||||
.ConfigureContainer<ContainerBuilder>(builder => |
||||
{ |
||||
builder.RegisterModule(new ConfigureAutofac()); |
||||
}); |
||||
|
||||
builder.Services.AddControllers(); |
||||
#endregion Autofac |
||||
|
||||
var app = builder.Build(); |
||||
// 设置全局默认请求体大小限制 |
||||
builder.WebHost.ConfigureKestrel(options => |
||||
{ |
||||
options.Limits.MaxRequestBodySize = 200 * 1024 * 1024; // 默认 200MB |
||||
}); |
||||
|
||||
// Configure the HTTP request pipeline. |
||||
var app = builder.Build(); |
||||
|
||||
app.UseHttpsRedirection(); |
||||
if (app.Environment.IsDevelopment()) |
||||
{ |
||||
app.UseSwagger(); |
||||
app.UseSwaggerUI(c => |
||||
{ |
||||
c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "WeiCloud.IoT-v1.0"); |
||||
}); |
||||
} |
||||
|
||||
app.UseAuthorization(); |
||||
// app.UseHttpsRedirection(); |
||||
|
||||
// app.UseAuthorization(); |
||||
|
||||
app.MapControllers(); |
||||
app.MapControllers(); |
||||
app.MapGet("/healthz", () => Results.Ok("OK")); |
||||
|
||||
app.Run(); |
||||
// 创建 Startup 实例 |
||||
var startup = new Startup(builder.Configuration); |
||||
startup.Configure(app, app.Environment, builder.Configuration); |
||||
app.Run(); |
||||
} |
||||
catch (Exception exception) |
||||
{ |
||||
// NLog: catch setup errors |
||||
logger.Error(exception, "Stopped program because of exception"); |
||||
throw; |
||||
} |
||||
finally |
||||
{ |
||||
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) |
||||
NLog.LogManager.Shutdown(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue