コード例 #1
0
        /// <summary>
        /// Method to configure services.
        /// </summary>
        /// <param name="services">Service Collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);

            DependencyInjector.RegisterServices(services);
            DependencyInjector.AddAutoMapper();
            DependencyInjector.AddDbContext(this.Configuration);

            Log.Logger = new LoggerConfiguration().MinimumLevel.Information()
                         .WriteTo.RollingFile("log-{Date}.txt", LogEventLevel.Information)
                         .WriteTo.Seq(this.Configuration["SeqUrl"])
                         .CreateLogger();

            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddSerilog();
            services.AddSingleton(loggerFactory);

            services.AddDiscoveryClient(this.Configuration);

            var mvcBuilder = services.AddMvc();

            mvcBuilder.AddMvcOptions(p => p.Filters.Add(new CustomActionFilterAttribute(Log.Logger)));
            mvcBuilder.AddMvcOptions(p => p.Filters.Add(new CustomExceptionFilterAttribute(Log.Logger)));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "Api Users",
                    Description = "Api para información de usuarios",
                    Contact     = new Microsoft.OpenApi.Models.OpenApiContact
                    {
                        Name = "Axity",
                        Url  = new System.Uri(AXITYURL),
                    },
                });
            });

            services.Configure <GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Fastest);
            services.AddResponseCompression();
        }