///<summary>
 ///Get this configuration set from a specific config file
 ///</summary>
 public LogWriterConfigSection Open(string path)
 {
     if ((object)instance == null)
     {
         if (path.EndsWith(".config",
                     StringComparison.InvariantCultureIgnoreCase))
             spath = path.Remove(path.Length - 7);
         else
             spath = path;
         Configuration config = ConfigurationManager.OpenExeConfiguration(spath);
         if (config.Sections["LogWriterConfigSection"] == null)
         {
             instance = new LogWriterConfigSection();
             config.Sections.Add("LogWriterConfigSection", instance);
             config.Save(ConfigurationSaveMode.Modified);
         }
         else
             instance =
                 (LogWriterConfigSection)config.Sections["LogWriterConfigSection"];
     }
     return instance;
 }
예제 #2
0
 // Процедура сохранения параметров логирования
 private void SaveLogParameters()
 {
     // Инициализируем конфиг для лог файла
     LogWriterConfigSection logWriterConfigSection = new LogWriterConfigSection();
     logWriterConfigSection.Open();
     // Сохраним в него наши данные
     logWriterConfigSection.logDir = textBoxLogDir.Text;
     logWriterConfigSection.logFileName = textBoxFileName.Text;
     logWriterConfigSection.maxLogAge = (int)numericUpDownMaxLogAge.Value;
     logWriterConfigSection.queueSize = (int)numericUpDownQueueSize.Value;
     if (checkBoxUseExternalLibrary.Checked) logWriterConfigSection.externalLogLib = null;
     else logWriterConfigSection.externalLogLib = textBoxExternalLogLib.Text;
     // Зафиксируем в файле
     logWriterConfigSection.Save();
     // Обновим параметры у нашего logWriter-а
     logWriter.LogDir = textBoxLogDir.Text;
     logWriter.LogFileName = textBoxFileName.Text;
     logWriter.MaxLogAge = (int)numericUpDownMaxLogAge.Value;
     logWriter.QueueSize = (int)numericUpDownQueueSize.Value;
 }