public Application Build() { if (config == null) { throw new ArgumentNullException("No configuration provided"); } AddCoreServices(config, serviceContainer); libraries.UseLogger(Log.Logger); libraries.ConfigureServices(serviceContainer); var services = serviceContainer.BuildServiceProvider(); libraries.Configure(services); return(services.GetService <Application>()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #if DEBUG Serilog.Debugging.SelfLog.Enable( msg => { System.Diagnostics.Debug.WriteLine(msg); System.Console.WriteLine(msg); } ); #endif Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config.GetSection("Packages")) .Enrich.WithExceptionDetails() .CreateLogger(); services.AddSingleton( (svc) => Log.Logger ); services.AddLogging( // redirect default Microsoft Logger to Serilog builder => builder.AddSerilog(dispose: false) ); services.AddMvc( options => { options.FormatterMappings.SetMediaTypeMappingForFormat("txt", new MediaTypeHeaderValue("text/plain")); options.OutputFormatters.Insert(0, new MonthlyReportTxtOutputFormatter()); } ).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped <IPairRepository, EfPairRepository>(); services.Configure <ApiControlerOptions>(config.GetSection("ApiControlerOptions")); ConfigureScheduledTasks(services); libraries.UseLogger(Log.Logger); libraries.ConfigureServices(services); }