Exemple #1
0
 /// <summary>
 /// Refreshes configuration settings for the NlogLogger from the configuration file.
 /// </summary>
 public override void RefreshConfiguration()
 {
     try
     {
         base.RefreshConfiguration();
         LoggingSection         loggingSection         = LoggingSection.GetSection();
         LoggingSettingsElement loggingSettingsElement = loggingSection.LoggingSettings;
         _logFolder            = loggingSettingsElement.LogFolder;
         _forwardToEventLogger = loggingSettingsElement.ForwardToEventLogger;
         // Set eventSources according to the configuration.
         _eventSources = new SortedList <int, EventRange>();
         LoggingSourceCollection eventSourcesCollection = loggingSection.LoggingSettings.Sources;
         foreach (LoggingSourceElement eventSourceElement in eventSourcesCollection)
         {
             string   source    = eventSourceElement.Name;
             int      min       = 0;
             int      max       = 0;
             string   ranges    = eventSourceElement.Range;
             string[] rangeList = ranges.Split(',');
             foreach (string range in rangeList)
             {
                 int pos = range.IndexOf('-');
                 if ((pos <= 0) || (pos >= range.Length - 1))
                 {
                     throw new Exception("Invalid format for event range. Expected hyphen between min and max values.");
                 }
                 else
                 {
                     try
                     {
                         min = Int32.Parse(range.Substring(0, pos));
                         max = Int32.Parse(range.Substring(pos + 1));
                     }
                     catch (Exception exception)
                     {
                         throw new Exception("Invalid format for event range. Could not parse min and max values.", exception);
                     }
                     EventRange eventRange = new EventRange(min, max, source);
                     _eventSources.Add(min, eventRange);
                 }
             }
         }
         // Set the eventIdFilter according to the configuration.
         _eventIdFilter = loggingSection.LoggingSettings.EventIdFilter;
         if (_eventIdFilter != null)
         {
             _eventIdFilter = "," + _eventIdFilter + ",";
         }
     }
     catch (Exception exception)
     {
         Logger.WriteWarning("The configuration for the NlogLogger could not be loaded from the application configuration file. Default values will be used.", 151);
         throw exception;
     }
 }
Exemple #2
0
        /// <summary>
        /// Gets the event source associated with a given eventId.
        /// </summary>
        /// <param name="eventId">The eventId to look up.</param>
        /// <returns>The event source associated with the eventId.</returns>
        public string GetEventSource(int eventId)
        {
            string eventSource = _defaultEventSource;

            if (_eventSources != null && _eventSources.Count > 0)
            {
                IEnumerator <KeyValuePair <int, EventRange> > enumerator = _eventSources.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    EventRange eventRange = enumerator.Current.Value;
                    if (eventRange.Includes(eventId))
                    {
                        eventSource = eventRange.Source;
                        break;
                    }
                }
            }
            return(eventSource);
        }