forked from zhontai/Admin.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (73 loc) · 2.57 KB
/
Program.cs
File metadata and controls
76 lines (73 loc) · 2.57 KB
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
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using NLog;
using NLog.Web;
using Autofac.Extensions.DependencyInjection;
using Admin.Core.Common.Helpers;
using Admin.Core.Common.Configs;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
using System.Threading.Tasks;
//using NLog.Extensions.Logging;
namespace Admin.Core
{
public class Program
{
private static AppConfig appConfig = new ConfigHelper().Get<AppConfig>("appconfig") ?? new AppConfig();
public static async Task<int> Main(string[] args)
{
var logger = LogManager.GetCurrentClassLogger();
try
{
Console.WriteLine("launching...");
var host = CreateHostBuilder(args).Build();
Console.WriteLine($"{string.Join("\r\n", appConfig.Urls)}\r\n");
await host.RunAsync();
return 0;
}
catch (Exception ex)
{
logger.Error(ex, "Stopped program because of exception");
return 1;
}
finally
{
LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
//使用logconfig.json配置,默认使用nlog.config
//var logConfig = new ConfigHelper().Load("logconfig", reloadOnChange: true).GetSection("nLog");
//LogManager.Configuration = new NLogLoggingConfiguration(logConfig);
return Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
//.UseEnvironment(Environments.Production)
.UseStartup<Startup>()
.ConfigureAppConfiguration((host, config) =>
{
if (appConfig.RateLimit)
{
config.AddJsonFile("./configs/ratelimitconfig.json", optional: false, reloadOnChange: true)
#if DEBUG
.AddJsonFile("./configs/ratelimitconfig.Development.json", true)
#endif
;
}
})
.UseUrls(appConfig.Urls);
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
})
.UseNLog();
}
}
}