Thursday, December 19, 2013

log4net configuration - one file per month



You want to have an external log4net.config file and also need one log file per month.

using log4net;
public class MyClass
{
    private static readonly ILog Logger = LogManager.GetLogger(typeof(MyClass));

    public Test()
    {
        //For debugging, To check if log4net configured correctly
        bool log4netIsConfigured = log4net.LogManager.GetRepository().Configured;

        Logger.Info("This is my log");
    }
}

You need to add an appSettings key called "log4net.Config" and then you can put an app-relative path to an external log4net.config file in there and everything will automatically works.
That file path is relative to the application base directory (AppDomain.CurrentDomain.BaseDirectory), so if you put the external log4net file in the root of the application, for console applications, file path would be "../../log4net.config" and for web applications, It would be "log4net.config".

web.config

  
    
  


log4net.config

    
      
       
      
            
       
      
       
      
      
        
      
    
    
      
      
    
  

2 comments:

Blog27999 said...

If you're trying to burn fat then you need to start following this brand new custom keto plan.

To create this keto diet service, licensed nutritionists, personal trainers, and professional cooks have joined together to develop keto meal plans that are productive, suitable, economically-efficient, and fun.

Since their launch in 2019, 1000's of clients have already remodeled their body and health with the benefits a good keto plan can offer.

Speaking of benefits; clicking this link, you'll discover eight scientifically-tested ones given by the keto plan.

Blogger said...

Do this hack to drop 2 lbs of fat in 8 hours

Over 160k women and men are using a simple and SECRET "liquid hack" to lose 1-2 lbs each and every night while they sleep.

It's very simple and it works all the time.

Just follow these easy step:

1) Take a drinking glass and fill it half full

2) Now learn this weight loss hack

you'll become 1-2 lbs skinnier the very next day!

Post a Comment