1 public class WebApiApplication : System.Web.HttpApplication 2 { 3 protected void Application_Start() 4 { 5 log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config"))); 6 AreaRegistration.RegisterAllAreas(); 7 GlobalConfiguration.Configure(WebApiConfig.Register); 8 FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 9 RouteConfig.RegisterRoutes(RouteTable.Routes); 10 BundleConfig.RegisterBundles(BundleTable.Bundles); 11 } 12 }
关键行在于
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config")));
之前试过
在AssemblyInfo.cs里面添加[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)],失败;
在WebApiConfig.cs里面添加log4net.Config.XmlConfigurator.Configure();,失败;
最后发现
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config")));,可行