using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using log4net;
using log4net.Config;
using log4net.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using OYW.OA.Application.Settings;
using OYW.OA.DTO;
using OYW.OA.DTO.Redis;
using OYW.OA.EFRepositories;
using OYW.OA.Infrastructure.Redis;
using OYW.OA.Web.Models;
namespace OYW.OA.Web
{
public class Startup
{
public static ILoggerRepository loggerRepository { get; set; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
loggerRepository = LogManager.CreateRepository("OYW.OA.Web");
XmlConfigurator.Configure(loggerRepository, new FileInfo("log4net.config"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler(x =>
{
x.Run(async context =>
{
var ex = context.Features.Get<Microsoft.AspNetCore.Diagnostics.IExceptionHandlerFeature>()?.Error;
ILog log = IocManager.Resolve<ILog>();
var msg = ex == null ? "发生错误。" : ex.Message;
log.Error(msg, ex);
context.Response.ContentType = "text/plain;charset=utf-8";
await context.Response.WriteAsync(msg);
});
});
}
}
}
x.Run(async context =>
{
var ex = context.Features.Get<Microsoft.AspNetCore.Diagnostics.IExceptionHandlerFeature>()?.Error;
ILog log = IocManager.Resolve<ILog>();
var msg = ex == null ? "发生错误。" : ex.Message;
log.Error(msg, ex);
context.Response.ContentType = "text/plain;charset=utf-8";
await context.Response.WriteAsync(msg);
});
});
}
}
}
第四节:OA权限管理系统(全局异常处理)
猜你喜欢
转载自blog.csdn.net/xiaoxionglove/article/details/80867720
今日推荐
周排行