log4.net动态修改存储路径位置(备忘)

/// <summary>
        /// 改变默认的日志位置
        /// </summary>
        /// <param name="folder"></param>
        public static void UpdateFolder(string folder)
        {
            var storedPath = LogManager.GetRepository();
            var appenders = storedPath.GetAppenders();
            //var targetFolder = appenders.First(m => m.Name.Equals("InfoAppender")) as RollingFileAppender;//如果是要指定改某个appender,则在这里指定appender
            //targetFolder.File = folder;
            
            //一般多种日志目录是写在一起
            if (appenders == null) return;
            foreach (var app in appenders)
            {
                if (app.Name.Equals("ErrorAppender") || app.Name.Equals("InfoAppender"))
                {
                    var ra = app as RollingFileAppender;
                    ra.File = folder;
                    ra.ActivateOptions();
                }
            }
        }

阅读更多
换一批

没有更多推荐了,返回首页