private static WebApplication BuildWebApplication(Application application, HostOptions options, ILogEventSink?sink) { var args = new List <string>(); if (options.Port.HasValue) { args.Add("--port"); args.Add(options.Port.Value.ToString(CultureInfo.InvariantCulture)); } var builder = WebApplication.CreateBuilder(args.ToArray()); // Logging for this application builder.Host.UseSerilog((context, configuration) => { configuration .MinimumLevel.Verbose() .Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore")) .Filter.ByExcluding(Matching.FromSource("Microsoft.Extensions")) .Filter.ByExcluding(Matching.FromSource("Microsoft.Hosting")) .Enrich .FromLogContext() .WriteTo .Console(); if (sink is object) { configuration.WriteTo.Sink(sink, LogEventLevel.Verbose); } }); builder.Services.AddRazorPages(o => o.RootDirectory = "/Dashboard/Pages"); builder.Services.AddServerSideBlazor(); builder.Services.AddOptions <StaticFileOptions>() .PostConfigure(o => { var fileProvider = new ManifestEmbeddedFileProvider(typeof(TyeHost).Assembly, "wwwroot"); // Make sure we don't remove the existing file providers (blazor needs this) o.FileProvider = new CompositeFileProvider(o.FileProvider, fileProvider); }); builder.Services.AddCors( options => { options.AddPolicy( "default", policy => { policy .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); builder.Services.AddSingleton(application); var app = builder.Build(); return(app); }
private IHost BuildWebApplication(Application application, HostOptions options, ILogEventSink?sink) { return(Host.CreateDefaultBuilder() .UseSerilog((context, configuration) => { var logLevel = options.LogVerbosity switch { Verbosity.Quiet => LogEventLevel.Warning, Verbosity.Info => LogEventLevel.Information, Verbosity.Debug => LogEventLevel.Verbose, _ => default }; configuration .MinimumLevel.Is(logLevel) .Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore")) .Filter.ByExcluding(Matching.FromSource("Microsoft.Extensions")) .Filter.ByExcluding(Matching.FromSource("Microsoft.Hosting")) .Enrich .FromLogContext() .WriteTo .Console(); if (sink is object) { configuration.WriteTo.Sink(sink, logLevel); } }) .ConfigureWebHostDefaults(builder => { var port = ComputePort(options.Port ?? application.DashboardPort); _computedPort = port; builder.Configure(ConfigureApplication) .UseUrls($"http://127.0.0.1:{port}"); builder.ConfigureAppConfiguration((b, c) => { b.HostingEnvironment.ApplicationName = "Microsoft.Tye.Hosting"; }); }) .ConfigureServices(services => { services.AddRazorPages(o => { o.RootDirectory = "/Dashboard/Pages"; }); services.AddServerSideBlazor(); services.AddOptions <StaticFileOptions>() .PostConfigure(o => { var fileProvider = new ManifestEmbeddedFileProvider(typeof(TyeHost).Assembly, "wwwroot"); // Make sure we don't remove the existing file providers (blazor needs this) o.FileProvider = new CompositeFileProvider(o.FileProvider, fileProvider); }); services.AddCors( options => { options.AddPolicy( "default", policy => { policy .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddSingleton(application); }) .Build()); }