|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.IO;
|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Threading.Tasks;
|
6 | 6 | using Microsoft.AspNetCore.Builder;
|
7 | 7 | using Microsoft.AspNetCore.Hosting;
|
8 | 8 | using Microsoft.Extensions.Configuration;
|
| 9 | +using Microsoft.Extensions.Hosting; |
9 | 10 | using Microsoft.Extensions.Logging;
|
10 | 11 | using Serilog;
|
11 | 12 |
|
12 | 13 | namespace ASPNETCoreAngularJWT
|
13 | 14 | {
|
14 | 15 | public class Program
|
15 | 16 | {
|
16 |
| - public static void Main(string[] args) |
| 17 | + public static void Main(string[] args) |
17 | 18 | {
|
18 |
| - var webHost = new WebHostBuilder() |
19 |
| - .UseKestrel() |
20 |
| - .UseContentRoot(Directory.GetCurrentDirectory()) |
21 |
| - .ConfigureAppConfiguration((hostingContext, config) => |
22 |
| - { |
23 |
| - var env = hostingContext.HostingEnvironment; |
24 |
| - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
25 |
| - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); |
26 |
| - config.AddEnvironmentVariables(); |
27 |
| - |
28 |
| - Log.Logger = new LoggerConfiguration().MinimumLevel.Error().WriteTo.RollingFile(Path.Combine(env.ContentRootPath,"logs/{Date}.txt")).CreateLogger(); |
29 |
| - }) |
30 |
| - .ConfigureLogging((hostingContext, logging) => |
31 |
| - { |
32 |
| - logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); |
33 |
| - logging.AddSerilog(dispose: true); |
34 |
| - logging.AddConsole(); |
35 |
| - logging.AddDebug(); |
36 |
| - }) |
37 |
| - .UseStartup<Startup>() |
38 |
| - .Build(); |
39 |
| - |
40 |
| - webHost.Run(); |
| 19 | + CreateHostBuilder(args).Build().Run(); |
41 | 20 | }
|
| 21 | + |
| 22 | + public static IHostBuilder CreateHostBuilder(string[] args) => |
| 23 | + Host.CreateDefaultBuilder(args) |
| 24 | + .ConfigureWebHostDefaults(webBuilder => |
| 25 | + { |
| 26 | + webBuilder.UseStartup<Startup>(); |
| 27 | + }); |
42 | 28 | }
|
| 29 | + |
43 | 30 | }
|
0 commit comments