using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace IAuthenticationFilterTest.Filters
{
public class LogToFileAttribute : IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
StringBuilder message = new StringBuilder();
message.AppendLine(DateTime.Now.ToString());
message.AppendLine(filterContext.Exception.ToString());
string filePath = "~/App_Data/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath(filePath), message.ToString());
}
}
}
程式碼參考ASP.NET MVC5 網站開發美學
留言列表