Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            MyServiceProvider.ServiceProvider = app.ApplicationServices;
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            #region Swagger
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1");
                c.RoutePrefix = "";
            });
            #endregion

            app.UseRouting();

            app.UseAuthorization();

            #region FairLogs
            app.UseFairhrLogs();
            //全局异常?
            app.UseExceptionHandler(errorApp =>
            {
                errorApp.Run(async context =>
                {
                    FairhrLogs.Error("异常:" + context.Features.Get <IExceptionHandlerFeature>().Error.Message);
                    ResultData result = new ResultData()
                    {
                        Code  = 500,
                        Msg   = context.Features.Get <IExceptionHandlerFeature>().Error.Message,
                        Count = 0,
                        Data  = ""
                    };
                    await context.Response.WriteAsync(JsonHelper.NewtonsoftSerialiize(result));
                });
            });
            #endregion


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (!env.IsProduction())
            {
                app.UseDeveloperExceptionPage();
            }

            #region 添加swagger
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/SupplierApi/swagger.json", "Supplier");
                c.RoutePrefix = string.Empty;
            });
            #endregion



            #region 添加日志平台
            app.UseFairhrLogs();
            app.UseExceptionHandler(errorApp =>
            {
                errorApp.Run(async context =>
                {
                    FairhrLogs.Error("异常:" + context.Features.Get <IExceptionHandlerFeature>().Error.Message);
                    ResultData result = new ResultData()
                    {
                        Code  = 500,
                        Msg   = context.Features.Get <IExceptionHandlerFeature>().Error.Message,
                        Count = 0,
                        Data  = ""
                    };
                    await context.Response.WriteAsync(JsonSerializer.Serialize(result));
                });
            });
            #endregion

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }