读取log4net配置文件方法

来源:互联网 发布:哈利波特电影3知乎 编辑:程序博客网 时间:2024/04/29 08:31
//读取log4net配置文件,推荐方法二/* ------------ 方法一(Start) ------------------------*///默认路径为根目录//未指定配置文件,默认监视Web.config//[assembly: log4net.Config.XmlConfigurator(Watch = true)]//and if you're using log4net.config file, use it like that instead://[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]//可指定路径//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Practice/log4net.config", Watch = true)]/* ------------ 方法一(End) ------------------------*//* ------------ 方法二(Start) ------------------------ * Application_Start事件中读取配置文件 * //注意:指明绝对路径 * //log4net.config为自定义的配置文件 * log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Practice/log4net.config"))); * //OR * log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config"))); * //OR * //当配置文件有变化时,重新加载(推荐) * log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~/Web.config"))); ------------ 方法二(End) ------------------------*/


方法三:在实例化日志对象时读取日志配置文件(无顺序限制,记录日志之前读取日志配置文件即可)

log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config")));log4net.ILog log =    log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


原创粉丝点击