C# – Changing log4Net logging path at runtime

        private static void InitLoggingPath()
            string progDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            string dataPath = progDataPath + Resource.DATA_FILES_PATH;
            if (!Directory.Exists(dataPath))

            if (Directory.Exists(dataPath))
                string configPath = Path.Combine(dataPath, "Test.txt");

                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[] appenders = repository.GetAppenders();
                var rollingAppender = appenders.Where(p => p is RollingFileAppender).ToList();
                foreach (IAppender appender in rollingAppender)
                    RollingFileAppender fileAppender = appender as RollingFileAppender;
                    fileAppender.File = configPath;
This entry was posted in .NET, Programming and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s