Created
October 10, 2019 21:26
-
-
Save 2garryn/d824234961e1ad3a83d1e86522c87e3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Serilog; | |
using Serilog.Filters; | |
using Serilog.Events; | |
namespace WebTemplateLib2 | |
{ | |
public class WebTemplateBuilder | |
{ | |
public static WebConfig Config; | |
public static void Main(string[] args) | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.Enrich.FromLogContext() | |
// .Filter.ByExcluding(Matching.FromSource("Microsoft")) | |
// .Filter.ByExcluding(Matching.FromSource("System")) | |
.MinimumLevel.Information() | |
.WriteTo.Console | |
( | |
LogEventLevel.Verbose, | |
"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] ({CorrelationToken}) {SourceContext} - {Message}{NewLine}{Exception}" | |
) | |
.CreateLogger(); | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseSerilog(); | |
webBuilder.UseUrls("http://*:" + Config.Port.ToString()); | |
webBuilder.UseStartup<Startup>(); | |
}); | |
} | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
if (WebTemplateBuilder.Config.Configurator != null) | |
{ | |
WebTemplateBuilder.Config.Configurator(services); | |
} | |
services.AddControllers(); | |
var s = services.AddMvcCore(); | |
foreach (var assembly in WebTemplateBuilder.Config.Controllers) | |
{ | |
s.AddApplicationPart(assembly).AddControllersAsServices(); | |
}; | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment