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 130247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:55:04+00:00 2026-05-11T05:55:04+00:00

I am trying to find somebody smarter than me to validate some syntax I

  • 0

I am trying to find somebody smarter than me to validate some syntax I wrote up. The idea is to configure the filename of my RollingFileAppender to the name of the assembly in order to make it more re-usable for my projects.

I’ve seen this previous SO article but it wasn’t exactly able to answer my question…

I’ve had a dickens of a time trying to understand the inner components of Log4net and this is what I came up with (residing in the Global.asax file – Application_Start method):

// Bind to the root hierarchy of log4net log4net.Repository.Hierarchy.Hierarchy root =    log4net.LogManager.GetRepository()      as log4net.Repository.Hierarchy.Hierarchy;  if (root != null) {   // Bind to the RollingFileAppender   log4net.Appender.RollingFileAppender rfa =      (log4net.Appender.RollingFileAppender)root.Root.GetAppender('RollingLogFileAppender');    if (rfa != null)   {     // Set the file name based on the assembly name     string filePath =        string.Format('~/App_Data/{0}.log', GetType().Assembly.GetName().Name);      // Assign the value to the appender     rfa.File = Server.MapPath(filePath);      // Apply changes to the appender     rfa.ActivateOptions();   } } 

Can anyone tell me, ‘this is hideous’, or ‘this should work fine’? Also, if I set the file dynamically can I still expect the log4net behavior to rotate the files based on the log4net.config file settings?

Much appreciated!

  • 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. 2026-05-11T05:55:05+00:00Added an answer on May 11, 2026 at 5:55 am

    You are doing this the hard way! Define your log4net config as XML in your application’s configuration file and use %property{} to advantage:

    <appender name='YourAppender' type='log4net.Appender.RollingFileAppender'>   <file type='log4net.Util.PatternString' value='~/App_Data/%property{LogName}' />   .... </appender> 

    This is dynamic — you just have to set the log4net property ‘LogName‘ before you initialize log4net. Thus, in your code any time before you configure log4net, set the desired value of this property:

    string LogName = GetType().Assembly.GetName().Name + '.log'; log4net.GlobalContext.Properties['LogName'] = LogName; 

    Of course, you may use any property name. I’ve chosen ‘LogName’ for a simple example, but you can have one per application if you want, as long as your code knows what the correct property name is and what the correct value should be.

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

Sidebar

Related Questions

Hope somebody could help me out, I am trying to find a solution for
Trying to find a way to remove blank pages from a document I wrote
Trying to find a good name for a method swapping each coordinate X and
I've spent some time trying to find an elegant and cross browser solution but
i'm trying to set up the selenium-maven-plugin and having some difficulties i hope somebody
I have been trying to find some more information about the next Microsoft Dynamics
In brief... I'm trying to find a way to add some attributes to the
I am trying to find some plugin like the one, used in this website
Trying to find a standard. The CmdLet will process data - multiple input, defined
Trying to find out if it's possible to use SQLAlchemy on Heroku. Thanks.

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.