By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

log4net logger.File property. Error: "The given path's format is not supported."

Ravi L
P: 12
I need to configure log4net programmatically. I got the code for this from the net which lots of users happen are using. But when I get an error saying "The given path's format is not supported." at logger.ActivateOptions. the code is reproduced below:

Expand|Select|Wrap|Line Numbers
  1. public class Logger
  2. {
  3.         private PatternLayout _layout = new PatternLayout();
  4.         private const string LOG_PATTERN = "%d [%t] %-5p %m%n";
  5.  
  6.         public string DefaultPattern
  7.         {
  8.                 get { return LOG_PATTERN; }
  9.         }
  10.  
  11.     public Logger()
  12.     {
  13.         _layout.ConversionPattern = DefaultPattern;
  14.         _layout.ActivateOptions();
  15.     }
  16.  
  17.     public PatternLayout DefaultLayout
  18.     {
  19.         get { return _layout; }
  20.     }
  21.  
  22.     public void AddAppender(IAppender appender)
  23.     {
  24.         Hierarchy hierarchy = 
  25.                 (Hierarchy)LogManager.GetRepository();
  26.  
  27.         hierarchy.Root.AddAppender(appender);
  28.     }
  29.  
  30.     static Logger()
  31.     {
  32.         try
  33.         {
  34.             Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();            
  35.             PatternLayout patternLayout = new PatternLayout();
  36.  
  37.  
  38.             RollingFileAppender roller = new RollingFileAppender();            
  39.             roller.AppendToFile = true;
  40.             roller.RollingStyle = RollingFileAppender.RollingMode.Size;
  41.             roller.MaxSizeRollBackups = 4;
  42.             roller.MaximumFileSize = "10000KB";
  43.             roller.StaticLogFileName = true;            
  44.             roller.File = "c:\\errorlog\\dnservices.log";
  45.  
  46.             patternLayout.ConversionPattern = LOG_PATTERN;
  47.             patternLayout.ActivateOptions();
  48.             roller.Layout = patternLayout;
  49.             roller.ActivateOptions();
  50.             hierarchy.Root.AddAppender(roller);
  51.  
  52.             hierarchy.Root.Level = Level.All;
  53.             hierarchy.Configured = true;
  54.         }
  55.         catch (Exception)
  56.         {            
  57.             throw;
  58.         }
  59.     }
  60.  
  61.     public static ILog Create()
  62.     {
  63.         return LogManager.GetLogger("Logger");
  64.     }
  65. }
I am using Visual Studio 2010 for development. Will this make any difference. the log4net version is 1.2.0.10. Have spent a lot of time on this to end up with this error. Any help would be appreciated.

Thank you.

Ravi
May 9 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.