Esempio n. 1
0
        public override void Initialize(Configuration.LoggerConfigurationElement cfg)
        {
            base.Initialize(cfg);
            // Setup root path
            String appBaseDir = AppDomain.CurrentDomain.BaseDirectory;

            _rootPath = cfg.Parameters.Get <String>("RootPath");
            if (String.IsNullOrEmpty(_rootPath))
            {   // No root path configured, use application's base dir
                _rootPath = Path.Combine(appBaseDir, "/logs");
            }
            else
            {     // Has root path
                if (!Path.IsPathRooted(_rootPath))
                { // Relative path configured
                    _rootPath = Path.Combine(appBaseDir, _rootPath);
                }
            }
            // Make sure root dir exist
            if (!EnsureDirExist(_rootPath))
            {
                System.Diagnostics.Trace.TraceError("Cannot create directory {0}!", _rootPath);
            }
            // Get base name
            _baseName = cfg.Parameters.Get <String>("BaseName");
            if (String.IsNullOrEmpty(_baseName))
            {
                _baseName = "LOG";
            }
            // Get max size
            _maxSize = cfg.Parameters.Get <long>("MaxSize");
            // Calculate file name
            CalculateFileName();
        }
Esempio n. 2
0
 /// <summary>
 /// Initialize logger
 /// </summary>
 /// <param name="elemLogger">Logger configuration element</param>
 public virtual void Initialize(LoggerConfigurationElement cfg)
 {
     Enabled = cfg.Enabled;
     Synchronize = cfg.Synchronize;
     try
     {
         Severity = (EventSeverity)Enum.Parse(typeof(EventSeverity), cfg.Severity);
     }
     catch (Exception err)
     {
         throw new ConfigurationErrorsException(String.Format("Invalid value of Severity: {0}!", cfg.Severity), err);
     }
     if (!Synchronize)
     {   // Asynchronize mode, start backend thread
         StartBackgroundThread();
     }
 }