Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 792931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:04:16+00:00 2026-05-14T22:04:16+00:00

I started to play with log4net today and so far, I really like it.

  • 0

I started to play with log4net today and so far, I really like it. In order to preserve our current logging functionality, the app needs to create a new log file whenever the application is started. The log file name has the date and time stamp encoded in it. Currently, I’ve got log4net configured via an XmlConfigurator, which works great, except that the filename for my RollingFileAppender is hardcoded in the configuration XML file.

I’d like to continue to use the XmlConfigurator, but after calling Configure(), I want to get at the RollingFileAppender and, in code, change its file value to be a dynamically-generated string. The sample documentation online seems to be down right now, but I’ve poked through the SDK reference, and it looks like I could use the Heirarchy and GetAppenders() to do what I need to do. Am I on the right track?

Ok, I took a stab at this and tried the following code, which didn’t work:

private static readonly ILog _log = LogManager.GetLogger(typeof(GUI));
// in the config file, I've set the filename to example.log, and it works
XmlConfigurator.Configure(new FileInfo("log_config.xml"));
Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
if(hierarchy != null) {
    // get the appenders
    IAppender[] appenders = hierarchy.GetAppenders();
    // change the filename for the RollingFileAppender
    foreach( IAppender a in appenders) {
        RollingFileAppender rfa = a as RollingFileAppender;
        if(rfa == null)
            continue;
        rfa.File = "newfile.log"; // no runtime error, but doesn't work.
    }
}
_log.Info("Application started");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:04:17+00:00Added an answer on May 14, 2026 at 10:04 pm

    Do you in this case need the rolling file appender? If not I would expect that your code would create the desired result if you used the normal file appender.

    Edit: Maybe it works with the RollingFile Appender if you call ActivateOptions() on the appender.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting started with the Play Framework 2.0 (using current trunk 2.1-SNAPSHOT, Scala)
I've started to play with the Koala gem for a RoR app. I've already
I have started to play with xVal as my validation framework for an ASP.Net
I've just started to play with CodeIgniter 1.7.2 and imendialtly noticed that there is
I'm getting started with Play 2.0 by following along with the tutorial. I'm hitting
I have just started to play with Play framework (2.0) and I'm having some
I just started working with play, and I modified the way I'm doing a
After the release of MVC 2, I have started to check and play with
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like
Started to play around with Jenkins. Created new job and entered SVN repository URL.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.