parent
21a29230bb
commit
1a572fbb36
26 changed files with 425 additions and 62 deletions
@ -0,0 +1,15 @@ |
|||||||
|
namespace Video.API.Infrastructure |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// 配置AutoMapper |
||||||
|
/// </summary> |
||||||
|
public class AutoMapperProfile |
||||||
|
{ |
||||||
|
/// <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,123 @@ |
|||||||
|
using Autofac; |
||||||
|
using Autofac.Extensions.DependencyInjection; |
||||||
|
using Common.Shared.API.Infrastructure; |
||||||
|
using Microsoft.OpenApi.Models; |
||||||
|
using NLog; |
||||||
|
using NLog.Extensions.Logging; |
||||||
|
using NLog.Web; |
||||||
|
using System.Reflection; |
||||||
|
|
||||||
namespace Common.Shared.API |
namespace Common.Shared.API |
||||||
{ |
{ |
||||||
public class Program |
public class Program |
||||||
{ |
{ |
||||||
public static void Main(string[] args) |
public static void Main(string[] args) |
||||||
|
{ |
||||||
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); |
||||||
|
logger.Debug("init main"); |
||||||
|
try |
||||||
{ |
{ |
||||||
var builder = WebApplication.CreateBuilder(args); |
var builder = WebApplication.CreateBuilder(args); |
||||||
|
|
||||||
// Add services to the container. |
builder.Services.AddHttpContextAccessor(); |
||||||
|
builder.Services.AddHttpClient(); |
||||||
|
|
||||||
builder.Services.AddControllers(); |
builder.Services.AddControllers(); |
||||||
|
builder.Services.AddSingleton(builder.Configuration); |
||||||
|
|
||||||
|
#region Cors |
||||||
|
|
||||||
|
builder.Services.AddCors(options => |
||||||
|
{ |
||||||
|
options.AddPolicy("_myAllowSpecificOrigins", |
||||||
|
builder => |
||||||
|
{ |
||||||
|
builder.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 |
||||||
|
|
||||||
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()) |
||||||
|
.ConfigureContainer<ContainerBuilder>(builder => |
||||||
|
{ |
||||||
|
builder.RegisterModule(new ConfigureAutofac()); |
||||||
|
}); |
||||||
|
|
||||||
|
#endregion Autofac |
||||||
|
|
||||||
|
// 设置全局默认请求体大小限制 |
||||||
|
builder.WebHost.ConfigureKestrel(options => |
||||||
|
{ |
||||||
|
options.Limits.MaxRequestBodySize = 200 * 1024 * 1024; // 默认 200MB |
||||||
|
}); |
||||||
|
|
||||||
var app = builder.Build(); |
var app = builder.Build(); |
||||||
|
|
||||||
// Configure the HTTP request pipeline. |
if (app.Environment.IsDevelopment()) |
||||||
|
{ |
||||||
|
app.UseSwagger(); |
||||||
|
app.UseSwaggerUI(c => |
||||||
|
{ |
||||||
|
c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "WeiCloud.IoT-v1.0"); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
app.UseHttpsRedirection(); |
app.UseHttpsRedirection(); |
||||||
|
|
||||||
app.UseAuthorization(); |
app.UseAuthorization(); |
||||||
|
|
||||||
|
|
||||||
app.MapControllers(); |
app.MapControllers(); |
||||||
|
// 创建 Startup 实例 |
||||||
|
var startup = new Startup(builder.Configuration); |
||||||
|
startup.Configure(app, app.Environment, builder.Configuration); |
||||||
app.Run(); |
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(); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
Loading…
Reference in new issue