示例#1
0
        /// <summary>
        /// Adds a listener to the trace listen array
        /// </summary>
        /// <param name="listenerToAdd">Trace Listener you wish to add</param>
        /// <returns>true on success, false on fail.</returns>
        public static bool AddTraceListener(TraceListener listenerToAdd)
        {
            try
            {
                Trace.AutoFlush = true;
                var traceSourceSetting = TraceSourceSettingStore.GetTraceSourceSettings(_traceSourceName);
                if (traceSourceSetting == null)
                {
                    traceSourceSetting = new TraceSourceSetting(_traceSourceName, TraceLevel);
                }
                if (traceSourceSetting.TraceListeners == null)
                {
                    traceSourceSetting.TraceListeners = new Dictionary <string, TraceListener>();
                }

                if (traceSourceSetting.TraceListeners.ContainsKey(listenerToAdd.Name))
                {
                    return(true);
                }

                traceSourceSetting.TraceListeners.Add(listenerToAdd.Name, listenerToAdd);
                TraceSourceSettingStore.AddTraceSettingsToStore(traceSourceSetting);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceName"></param>
        /// <returns></returns>
        public static TraceSourceSetting GetTraceSourceSettings(string sourceName)
        {
            TraceSourceSetting settings = null;

            if (!string.IsNullOrEmpty(sourceName))
            {
                settings = TraceSourceSettingsCollection
                           .SingleOrDefault(x => String.Compare(x.SourceName, sourceName, StringComparison.OrdinalIgnoreCase) == 0);
            }
            return(settings);
        }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 public static void AddTraceSettingsToStore(TraceSourceSetting listnerSettings)
 {
     Trace.AutoFlush = true;
     if (listnerSettings != null)
     {
         var settings = TraceSourceSettingsCollection.SingleOrDefault(x => String.Compare(x.SourceName, listnerSettings.SourceName, StringComparison.OrdinalIgnoreCase) == 0);
         if (settings != null)
         {
             TraceSourceSettingsCollection.Remove(settings);
         }
         TraceSourceSettingsCollection.Add(listnerSettings);
     }
 }