-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
113 lines (99 loc) · 4.59 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using CodeM.FastApi.Common;
using CodeM.FastApi.Log;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using System.Threading;
namespace CodeM.FastApi
{
public class Program
{
private static string mEnv = null;
private static string mPort = null;
public static void Main(string[] args)
{
try
{
foreach (string arg in args)
{
string[] paramValues = arg.Split("=");
if (paramValues.Length == 2)
{
if ("env".Equals(paramValues[0].Trim(), StringComparison.OrdinalIgnoreCase))
{
mEnv = paramValues[1].Trim();
}
else if ("port".Equals(paramValues[0].Trim(), StringComparison.OrdinalIgnoreCase))
{
mPort = paramValues[1].Trim();
}
}
}
string frameworkName = " _____ ___ _____ _____ ___ _____ _ __ _ _____ _____ \n" +
"| ___| / | / ___/ |_ _| / | | _ \\ | | | \\ | | | ____| |_ _| \n" +
"| |__ / /| | | |___ | | / /| | | |_| | | | | \\| | | |__ | | \n" +
"| __| / /_| | \\___ \\ | | / /_| | | ___/ | | | |\\ | | __| | | \n" +
"| | / / | | ___| | | | / / | | | | | | _ | | \\ | | |___ | | \n" +
"|_| /_/ |_| /_____/ |_| /_/ |_| |_| |_| |_| |_| \\_| |_____| |_| \n" +
" \n" +
"===================================================================================";
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(frameworkName);
CreateHostBuilder(args).Build().Run();
}
catch (Exception exp)
{
if (Logger.Inited)
{
Logger.Instance().Fatal(exp);
Thread.Sleep(1000);
}
Process.GetCurrentProcess().Kill();
}
finally
{
Console.ForegroundColor = ConsoleColor.White;
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext, logging) =>
{
Console.WriteLine("开始启动......");
Console.WriteLine(string.Format("发现内容目录:{0}",
AppDomain.CurrentDomain.BaseDirectory));
logging.ClearProviders();
if (hostingContext.HostingEnvironment.IsDevelopment())
{
logging.AddDebug();
logging.AddConsole();
}
IConfigurationSection options = hostingContext.Configuration
.GetSection("Logging").GetSection("File").GetSection("Options");
logging.AddFile(options);
ILoggerFactory factory = logging.Services.BuildServiceProvider().GetService<ILoggerFactory>();
Logger.Init(factory);
})
.ConfigureWebHostDefaults(webBuilder =>
{
if (!string.IsNullOrWhiteSpace(mEnv))
{
webBuilder = webBuilder.UseEnvironment(mEnv);
}
if (!string.IsNullOrWhiteSpace(mPort))
{
webBuilder = webBuilder.UseUrls(string.Concat("http://*:", mPort));
}
webBuilder.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
});
webBuilder.UseStartup<Startup>();
FastApiUtils.SetEnvironmentName(webBuilder.GetSetting("ENVIRONMENT"));
});
}
}