Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using Serilog;
- using Serilog.Enrichers;
- using SimpleInjector;
- using SimpleInjector.Integration.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace SmsRouterApi
- {
- public class Startup
- {
- private Container container = new Container();
- public void ConfigureServices(IServiceCollection service)
- {
- service.AddMvc();
- service.AddSingleton<IControllerActivator>(new SimpleInjectorControllerActivator(container));
- }
- /// <summary>
- /// The configure.
- /// </summary>
- /// <param name="app">
- /// The app.
- /// </param>
- /// <param name="host">
- /// The host.
- /// </param>
- /// <param name="loggerFactory">
- /// The logger factory.
- /// </param>
- public void Configure(IApplicationBuilder app, IHostingEnvironment host, ILoggerFactory loggerFactory)
- {
- Log.Logger = new LoggerConfiguration()
- .WriteTo.File("Logs/AspnetCoreWebAPISelfHost.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}")
- .WriteTo.LiterateConsole()
- .Enrich.With(new ThreadIdEnricher())
- .MinimumLevel.Debug()
- .CreateLogger();
- loggerFactory.AddSerilog();
- var logger = loggerFactory.CreateLogger("application");
- app.UseSimpleInjectorAspNetRequestScoping(this.container);
- this.container.RegisterMvcControllers(app);
- this.container.RegisterSingleton(logger);
- app.UseMvc();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement