protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/log4net.config"))); }
public class LogController : Controller { // // GET: /Log/ public ActionResult Index() { WriteLog(DateTime.Now.ToString()); return View(); } public static void WriteLog(string txt) { ILog log = LogManager.GetLogger("log4netlogger"); log.Error(txt); } }
PM> install-package log4net
已安装“log4net 2.0.3”。正在将“log4net 2.0.3”添加到 WebApplication7。已成功将“log4net 2.0.3”添加到 WebApplication7。
当前版本为 1.2.13.0
CREATE TABLE [dbo].[Log] (
[Id] [int] IDENTITY (1, 1) NOT NULL, [Date] [datetime] NOT NULL, [Thread] [varchar] (255) NOT NULL, [Level] [varchar] (50) NOT NULL, [Logger] [varchar] (255) NOT NULL, [Message] [varchar] (4000) NOT NULL, [Exception] [varchar] (2000) NULL)