Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Mvc.Controllers;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Logging;
  6. using Serilog;
  7. using Serilog.Enrichers;
  8. using SimpleInjector;
  9. using SimpleInjector.Integration.AspNetCore.Mvc;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14.  
  15. namespace SmsRouterApi
  16. {
  17. public class Startup
  18. {
  19. private Container container = new Container();
  20. public void ConfigureServices(IServiceCollection service)
  21. {
  22. service.AddMvc();
  23.  
  24. service.AddSingleton<IControllerActivator>(new SimpleInjectorControllerActivator(container));
  25.  
  26. }
  27.  
  28. /// <summary>
  29. /// The configure.
  30. /// </summary>
  31. /// <param name="app">
  32. /// The app.
  33. /// </param>
  34. /// <param name="host">
  35. /// The host.
  36. /// </param>
  37. /// <param name="loggerFactory">
  38. /// The logger factory.
  39. /// </param>
  40. public void Configure(IApplicationBuilder app, IHostingEnvironment host, ILoggerFactory loggerFactory)
  41. {
  42.  
  43. Log.Logger = new LoggerConfiguration()
  44. .WriteTo.File("Logs/AspnetCoreWebAPISelfHost.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}")
  45. .WriteTo.LiterateConsole()
  46. .Enrich.With(new ThreadIdEnricher())
  47. .MinimumLevel.Debug()
  48. .CreateLogger();
  49.  
  50. loggerFactory.AddSerilog();
  51.  
  52. var logger = loggerFactory.CreateLogger("application");
  53. app.UseSimpleInjectorAspNetRequestScoping(this.container);
  54.  
  55. this.container.RegisterMvcControllers(app);
  56. this.container.RegisterSingleton(logger);
  57.  
  58.  
  59.  
  60. app.UseMvc();
  61.  
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement