异常过虑器

public class ErrorAttribute : HandleErrorAttribute
{

    public override void OnException(ExceptionContext filterContext)
    {
        base.OnException(filterContext);
        string path = filterContext.HttpContext.Server.MapPath("~/Exception.txt");
        using (StreamWriter sw = System.IO.File.AppendText(path))
        {
            sw.WriteLine(DateTime.Now.ToString() + ":" + filterContext.Exception.Message);
        }
    }

}
原文地址:https://www.cnblogs.com/genesis/p/5513824.html