56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace JiShe.IoT;
|
|
|
|
public class Program
|
|
{
|
|
public static async Task<int> Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
Log.Information("JiShe.IoT.HttpApi.Host.");
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.Host
|
|
.AddAppSettingsSecretsJson()
|
|
.UseAutofac()
|
|
.UseSerilog((context, loggerConfiguration) =>
|
|
{
|
|
SerilogToEsExtensions.SetSerilogConfiguration(
|
|
loggerConfiguration,
|
|
context.Configuration);
|
|
})
|
|
.ConfigureAppConfiguration((context, builder) =>
|
|
{
|
|
var env = context.HostingEnvironment.EnvironmentName;
|
|
Log.Information("µ±Ç°»·¾³ £º" + env);
|
|
string[] filePathArray = new string[] { Environment.CurrentDirectory, "configs" };
|
|
string jsonPath = Path.Combine(filePathArray);
|
|
|
|
builder.AddJsonFile(Path.Combine(jsonPath, "appsettings.json"), false, true);
|
|
builder.AddJsonFile(Path.Combine(jsonPath, $"appsettings.{env}.json"), false, true);
|
|
});
|
|
|
|
await builder.AddApplicationAsync<JiShe.IoT.IoTHttpApiHostModule>();
|
|
builder.WebHost.ConfigureKestrel((context, options) => { options.Limits.MaxRequestBodySize = 1024 * 50; });
|
|
builder.WebHost.UseUrls($"http://+:10500");
|
|
var app = builder.Build();
|
|
await app.InitializeApplicationAsync();
|
|
await app.RunAsync();
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is HostAbortedException)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
Log.Fatal(ex, "Host terminated unexpectedly!");
|
|
return 1;
|
|
}
|
|
finally
|
|
{
|
|
await Log.CloseAndFlushAsync();
|
|
}
|
|
}
|
|
} |