/// <summary> /// Initializes a new instance of the <see cref="AsynchronousTraceListenerWrapper" /> class. /// </summary> /// <param name="wrappedTraceListener">The wrapped trace listener.</param> /// <param name="ownsWrappedTraceListener">Indicates whether the wrapper should dispose the wrapped trace listener.</param> /// <param name="bufferSize">Size of the buffer for asynchronous requests.</param> /// <param name="maxDegreeOfParallelism">The max degree of parallelism for thread safe listeners. Specify <see langword="null"/> to use the current core count.</param> /// <param name="disposeTimeout">The timeout for waiting to complete buffered requests when disposing. When <see langword="null" /> the default of <see cref="Timeout.InfiniteTimeSpan" /> is used.</param> public AsynchronousTraceListenerWrapper( TraceListener wrappedTraceListener, bool ownsWrappedTraceListener = true, int? bufferSize = DefaultBufferSize, int? maxDegreeOfParallelism = null, TimeSpan? disposeTimeout = null) { Guard.ArgumentNotNull(wrappedTraceListener, "wrappedTraceListener"); CheckBufferSize(bufferSize); CheckMaxDegreeOfParallelism(maxDegreeOfParallelism); CheckDisposeTimeout(disposeTimeout); this.wrappedTraceListener = wrappedTraceListener; this.ownsWrappedTraceListener = ownsWrappedTraceListener; this.disposeTimeout = disposeTimeout ?? Timeout.InfiniteTimeSpan; this.closeSource = new CancellationTokenSource(); this.requests = bufferSize != null ? new BlockingCollection<Action<TraceListener>>(bufferSize.Value) : new BlockingCollection<Action<TraceListener>>(); if (this.wrappedTraceListener.IsThreadSafe) { this.maxDegreeOfParallelism = maxDegreeOfParallelism.HasValue ? maxDegreeOfParallelism.Value : Environment.ProcessorCount; this.asyncProcessingTask = Task.Factory.StartNew(this.ProcessRequestsInParallel, CancellationToken.None, TaskCreationOptions.HideScheduler | TaskCreationOptions.LongRunning, TaskScheduler.Default); } else { this.asyncProcessingTask = Task.Factory.StartNew(this.ProcessRequests, CancellationToken.None, TaskCreationOptions.HideScheduler | TaskCreationOptions.LongRunning, TaskScheduler.Default); } }
// Add a TraceListener to a type public static void AddTraceListener(string type, TraceListener traceListener) { if (type == ListenerType.All) { lock (Tracers) { foreach (var tracerKey in Tracers.Keys) InternalAddListener(tracerKey, traceListener); } lock (TraceAll) { TraceAll.Add(traceListener); } } else { lock (Tracers) { if (!Tracers.ContainsKey(type)) throw new ArgumentException(string.Format("The trace type '{0}' must be registred before adding a trace listener.", type)); InternalAddListener(type, traceListener); } } }
private static void Main(string[] args) { var opts = new BenchmarkArgs(); if (CommandLine.Parser.ParseArgumentsWithUsage(args, opts)) { if (!string.IsNullOrEmpty(opts.LogFilePath)) { BenchmarkLogging.EnableFileLogging(opts.LogFilePath); var logStream = new FileStream(opts.LogFilePath + ".bslog", FileMode.Create); BrightstarListener = new TextWriterTraceListener(logStream); BrightstarDB.Logging.BrightstarTraceSource.Listeners.Add(BrightstarListener); BrightstarDB.Logging.BrightstarTraceSource.Switch.Level = SourceLevels.All; } } else { var usage = CommandLine.Parser.ArgumentsUsage(typeof (BenchmarkArgs)); Console.WriteLine(usage); } var runner = new BenchmarkRunner(opts); runner.Run(); BenchmarkLogging.Close(); BrightstarDB.Logging.BrightstarTraceSource.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="TraceOutputWindowPane"/> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="shellEvents">The shell events.</param> /// <param name="outputPaneId">The output pane GUID, which must be unique and remain constant for a given pane.</param> /// <param name="outputPaneTitle">The output pane title.</param> /// <param name="traceSourceNames">The names of the trace sources to write to the output window pane.</param> public TraceOutputWindowPane(IServiceProvider serviceProvider, IShellEvents shellEvents, Guid outputPaneId, string outputPaneTitle, params string[] traceSourceNames) { Guard.NotNull(() => serviceProvider, serviceProvider); Guard.NotNull(() => shellEvents, shellEvents); Guard.NotNullOrEmpty(() => outputPaneTitle, outputPaneTitle); Guard.NotNull(() => traceSourceNames, traceSourceNames); this.serviceProvider = serviceProvider; this.outputPaneGuid = outputPaneId; this.outputPaneTitle = outputPaneTitle; this.traceSourceNames = traceSourceNames; this.shellEvents = shellEvents; this.shellEvents.ShellInitialized += this.OnShellInitialized; // Create a temporary writer that buffers events that happen // before shell initialization is completed, so that we don't // miss anything. this.temporaryWriter = new StringWriter(CultureInfo.CurrentCulture); this.listener = new TextWriterTraceListener(this.temporaryWriter, this.outputPaneTitle); this.listener.IndentLevel = 4; this.listener.Filter = defaultFilter; this.AddListenerToSources(); }
/// <summary> /// Create a new instance of this trace manager /// </summary> public TraceSourceProvider(TraceListener listener) { // Create default source // source = new System.Diagnostics.TraceSource("TraceSourceApp", SourceLevels.All); if (listener != null) Source.Listeners.Add(listener); }
/// <devdoc> /// <para>Adds a <see cref='System.Diagnostics.TraceListener'/> to the list.</para> /// </devdoc> public int Add(TraceListener listener) { InitializeListener(listener); lock (TraceInternal.critSec) { return list.Add(listener); } }
public void AddTraceListener(TraceListener traceListener) { lock (this.syncRoot) { this.tracer.Listeners.Add(traceListener); } }
private static void AddListenerToSources(Collection<PSTraceSource> matchingSources, TraceListener listener) { foreach (PSTraceSource source in matchingSources) { source.Listeners.Add(listener); } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param name='application'> /// Root object of the host application. /// </param> /// <param name='connectMode'> /// Describes how the Add-in is being loaded. /// </param> /// <param name='addIn'> /// Object representing this Add-in. /// </param> /// /// <param name='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addIn, ref Array custom) { _application = (DTE2)application; _addIn = (AddIn)addIn; try { if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) { _listener = CreateTraceListener(); _env = new ControllerEnvironment(new WindowHandle(_application.MainWindow.HWnd), _listener); _controller = CreateController(); _controller.OnConnectionStateChange += OnConnectionStateChange; CreateCommands(); CreateToolWindow(); _listener.WriteLine("Addin initialized"); if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { OnStartupComplete(ref custom); } } } catch (Exception ex) { if (_listener != null) { _listener.WriteLine(ex); } } }
/// <summary> /// Adds a listener to the source with the given <paramref name="sourceName"/>. /// </summary> public static void AddListener(string sourceName, TraceListener listener) { Guard.NotNullOrEmpty(() => sourceName, sourceName); Guard.NotNull(() => listener, listener); Tracer.Instance.AddListener(sourceName, listener); }
/// <summary> /// Initalizes a new instance of <see cref="DatabaseTraceListener"/>. /// </summary> public DatabaseTraceListener() { fallbackTraceListener = new XmlWriterRollingTraceListener(2000000, "dblogfallback"); machineName = Environment.MachineName; modulePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; appDomainName = AppDomain.CurrentDomain.FriendlyName; }
public static void WriteAll(ActionResult output, TraceListener listener) { Trace.Listeners.Clear(); Trace.Listeners.Add(new ExtendedConsoleTraceListener()); foreach (var lineOutput in output.Output) { switch (lineOutput.TraceEventType) { case TraceEventType.Error: Trace.TraceError(lineOutput.Message); break; case TraceEventType.Warning: Trace.TraceWarning(lineOutput.Message); break; default: Trace.WriteLine(lineOutput.Message); break; } } if (output.Value != null) { Trace.TraceInformation(string.Format("=> {0}", output.Value.ToString())); } }
public void TraceListenerFilterOnMultipleCollectionsWithCommonElementsDoesNotRepeatElements() { TraceListenerFilter filter = new TraceListenerFilter(); TraceListener listener1 = new MockTraceListener(); TraceListener listener2 = new MockTraceListener(); IList traceListenersCollection1 = new TraceListener[] { listener1, listener2 }; TraceListener listener3 = new MockTraceListener(); TraceListener listener4 = new MockTraceListener(); IList traceListenersCollection2 = new TraceListener[] { listener2, listener3, listener4 }; int i = 0; Dictionary<TraceListener, int> listeners = new Dictionary<TraceListener, int>(); foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection1)) { i++; listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1; } foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection2)) { i++; listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1; } Assert.AreEqual(4, i); Assert.AreEqual(1, listeners[listener1]); Assert.AreEqual(1, listeners[listener2]); Assert.AreEqual(1, listeners[listener3]); Assert.AreEqual(1, listeners[listener4]); }
/// <summary> /// try, try, try... to move this file. tries for a predefined period, in case a very large file was copying, or times out /// note: blocks thread /// </summary> /// <param name="sourcePath">full path to source file</param> /// <param name="destinationPath">full path to destination file</param> /// <param name="logFile">log file to write to</param> /// <returns>true if file moved OK</returns> public static bool ResilientMoveFile (string sourcePath, string destinationPath, TraceListener logFile) { if (logFile != null) { logFile.WriteLine ("Moving file '" + sourcePath + "' to '" + destinationPath + "'"); } // it may have been created, but might not be finished copying. need to wait until we can have accessto move it bool haveMoved = false; int tryCount = 0; DateTime timeStart = DateTime.Now; while (!haveMoved) { // try to get access for predefined period if (DateTime.Now - timeStart > TimeSpan.FromSeconds (EncoderFolderWatcherService.WatcherSettings.Default.retryFileCopyDurationSeconds)) { throw new WatcherException (" Failed to get access to '" + sourcePath + "' within established time period -- abandoning"); } // try renaming file. if we dont have access we will get the IOException try { if (logFile != null) { logFile.WriteLine (" Trying to get access to '" + sourcePath + "'"); } File.Move (sourcePath, destinationPath); haveMoved = true; if (logFile != null) { logFile.WriteLine (" Moved file '" + sourcePath + "' to '" + destinationPath + "'"); } } catch (FileNotFoundException) { // source file moved underneath us (someone else claimed?) if (logFile != null) { logFile.WriteLine (" file '" + sourcePath + "' moved from underneath us. This machine should not do the encode"); } return false; } catch (IOException) { // did not have access. Wait a little if (logFile != null) { logFile.WriteLine (" Could not get access to '" + sourcePath + "' ... sleeping 1 second before retrying (try " + (++tryCount) + ")"); } Thread.Sleep (1000); } } return true; }
public static void Initialize(CompositionContainer container, ContentManager contentManager, AddInManager addInManager, NotificationManager notifications, TraceListener listener) { Instance = new App(container, contentManager, addInManager, notifications, listener); }
/// <summary> /// Attaches a text file based trace listener. /// </summary> /// <param name="szFile">Name of the trace file.</param> public static void AttachTraceListener(string szFile) { DetachTraceListener(); m_Listener = new TextWriterTraceListener(szFile); m_Listener.TraceOutputOptions = TraceOptions.DateTime; Debug.Listeners.Add(m_Listener); }
public void Start() { RequireNotStarted(); startupTraceListener = CreateTraceListener(); Trace.Source.Listeners.Add(startupTraceListener); startupTimer = Stopwatch.StartNew(); }
public static void AddListener(TraceListener listener) { if (listener == null) throw new ArgumentNullException("listener"); lock (listeners) listeners.Add(listener); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void AddRange(TraceListener[] value) { if (value == null) { throw new ArgumentNullException("value"); } for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) { this.Add(value[i]); } }
public void Insert(int index, TraceListener listener) { this.InitializeListener(listener); lock (TraceInternal.critSec) { this.list.Insert(index, listener); } }
public static void AddListener(TraceListener listener) { if (listeners.Contains(listener)) return; listeners.Add(listener); foreach (KeyValuePair<string, TraceSource> traceSource in traceSources) traceSource.Value.Listeners.Add(listener); }
public Setting() { m_xmldoc = new XmlDocument(); m_general = new Dictionary<string,string>(); string logName = AppDomain.CurrentDomain.FriendlyName; m_listener = new EventLogTraceListener(logName); Trace.Listeners.Add(m_listener); }
/// <summary> /// Adds the specified <see cref="TraceListener"/> to the special log source to work asynchronously. /// </summary> /// <param name="logSource">The special log source to add the trace listener to.</param> /// <param name="traceListener">The trace listener to add.</param> /// <param name="bufferSize">The size of the buffer for asynchronous requests.</param> /// <param name="maxDegreeOfParallelism">The max degree of parallelism for thread safe listeners. Specify <see langword="null"/> to use the current core count.</param> /// <param name="disposeTimeout">The timeout for waiting to complete buffered requests when disposing. When <see langword="null" /> the default of <see cref="System.Threading.Timeout.InfiniteTimeSpan" /> is used.</param> public static void AddAsynchronousTraceListener( this SpecialLogSourceData logSource, TraceListener traceListener, int? bufferSize = AsynchronousTraceListenerWrapper.DefaultBufferSize, int? maxDegreeOfParallelism = null, TimeSpan? disposeTimeout = null) { logSource.AddTraceListener(BuildAsynchronousWrapper(traceListener, bufferSize, maxDegreeOfParallelism, disposeTimeout)); }
private static TraceListener BuildAsynchronousWrapper(TraceListener traceListener, int? bufferSize, int? maxDegreeOfParallelism, TimeSpan? disposeTimeout) { return new AsynchronousTraceListenerWrapper(traceListener, bufferSize: bufferSize, maxDegreeOfParallelism: maxDegreeOfParallelism, disposeTimeout: disposeTimeout) { Name = traceListener.Name, Filter = traceListener.Filter }; }
internal void InitializeListener(TraceListener listener) { if (listener == null) { throw new ArgumentNullException("listener"); } listener.IndentSize = TraceInternal.IndentSize; listener.IndentLevel = TraceInternal.IndentLevel; }
public virtual void Setup() { Log.LogWrite += new Log.LogEventHandler(Log_LogWrite); System.Diagnostics.Trace.Listeners.Add(_myListener = new TraceListener()); _conOutSaved = Console.Out; Console.SetOut(_conOut = new StringWriter()); _conErrSaved = Console.Error; Console.SetError(_conErr = new StringWriter()); }
public DatabaseTraceListener(string storedProcedureName, string connectionStringName, TraceListener fallbackListener, IExtraDataTransformer extraLogDataTransformer ) : this() { this.storedProcedureName = storedProcedureName; this.connectionStringName = connectionStringName; fallbackTraceListener = fallbackListener; extraLogDataProvider = extraLogDataTransformer; }
public TraceLogWriterFactory() { _logs = new DictionaryCache<string, TraceLogWriter>(CreateTraceLog); _sources = new DictionaryCache<string, TraceSource>(CreateTraceSource); _defaultSource = new TraceSource("Default", SourceLevels.Information); _listener = AddDefaultConsoleTraceListener(_defaultSource); _sources.Get("Topshelf"); }
private void frm_DebugOutput_FormClosing(object sender, FormClosingEventArgs e) { Trace.WriteLine("Debug Output Console Closed"); Trace.Listeners.Remove(_traceListener); _flusherThread.Abort(); _flusherThread.Join(); _memoryStream.ContentsUpdated -= TraceUpdated; _traceListener = null; _memoryStream.Dispose(); _memoryStream.Close(); }
public void AddRange(TraceListener[] value) { if (value == null) { throw new ArgumentNullException("value"); } for (int i = 0; i < value.Length; i++) { this.Add(value[i]); } }
public TraceListener GetRuntimeObject() { if (_runtimeObject != null) { return((TraceListener)_runtimeObject); } try { string className = TypeName; if (String.IsNullOrEmpty(className)) { // Look it up in SharedListeners Debug.Assert(_allowReferences, "_allowReferences must be true if type name is null"); if (_attributes != null || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || TraceOutputOptions != TraceOptions.None || !String.IsNullOrEmpty(InitData)) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_listener_cant_have_properties, Name)); } if (DiagnosticsConfiguration.SharedListeners == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name)); } ListenerElement sharedListener = DiagnosticsConfiguration.SharedListeners[Name]; if (sharedListener == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name)); } else { _runtimeObject = sharedListener.GetRuntimeObject(); return((TraceListener)_runtimeObject); } } else { // create a new one TraceListener newListener = (TraceListener)BaseGetRuntimeObject(); newListener.initializeData = InitData; newListener.Name = Name; newListener.SetAttributes(Attributes); newListener.TraceOutputOptions = TraceOutputOptions; if ((Filter != null) && (Filter.TypeName != null) && (Filter.TypeName.Length != 0)) { newListener.Filter = Filter.GetRuntimeObject(); XmlWriterTraceListener listerAsXmlWriter = newListener as XmlWriterTraceListener; if (listerAsXmlWriter != null) { // This filter was added via configuration, which means we want the listener // to respect it for TraceTransfer events. listerAsXmlWriter.shouldRespectFilterOnTraceTransfer = true; } } _runtimeObject = newListener; return(newListener); } } catch (ArgumentException e) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, Name), e); } }
public void Remove(TraceListener listener) { throw new NotImplementedException(); }
/// <include file='doc\TraceListeners.uex' path='docs/doc[@for="TraceListenerCollection.Insert"]/*' /> /// <devdoc> /// <para>Inserts the listener at the specified index.</para> /// </devdoc> public void Insert(int index, TraceListener listener) { InitializeListener(listener); ((IList)this).Insert(index, listener); }
public bool Contains(System.Diagnostics.TraceListener listener) { throw null; }
/// <devdoc> /// <para>Gets the index of the specified listener.</para> /// </devdoc> public int IndexOf(TraceListener listener) { return(((IList)this).IndexOf(listener)); }
public int IndexOf(TraceListener listener) { return(listeners.IndexOf(listener)); }
public bool Contains(TraceListener listener) { return(listeners.Contains(listener)); }
private void InitializeListener(TraceListener listener) { listener.IndentLevel = TraceImpl.IndentLevel; listener.IndentSize = TraceImpl.IndentSize; }
public int Add(TraceListener listener) { InitializeListener(listener); return(listeners.Add(listener)); }
private static void HandleListeners(Hashtable config, XmlNode listenersNode, object context) { HandlerBase.CheckForUnrecognizedAttributes(listenersNode); foreach (XmlNode listenersChild in listenersNode.ChildNodes) { if (HandlerBase.IsIgnorableAlsoCheckForNonElement(listenersChild)) { continue; } string name = null, className = null, initializeData = null; string op = listenersChild.Name; switch (op) { case "add": case "remove": case "clear": break; default: HandlerBase.ThrowUnrecognizedElement(listenersChild); break; } HandlerBase.GetAndRemoveStringAttribute(listenersChild, "name", ref name); HandlerBase.GetAndRemoveStringAttribute(listenersChild, "type", ref className); HandlerBase.GetAndRemoveStringAttribute(listenersChild, "initializeData", ref initializeData); HandlerBase.CheckForUnrecognizedAttributes(listenersChild); HandlerBase.CheckForChildNodes(listenersChild); TraceListener newListener = null; if (className != null) { Type t = Type.GetType(className); if (t == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_find_type, className)); } if (!typeof(TraceListener).IsAssignableFrom(t)) { throw new ConfigurationErrorsException(SR.GetString(SR.Type_isnt_tracelistener, className)); } // create a listener with parameterless constructor if (initializeData == null) { ConstructorInfo ctorInfo = t.GetConstructor(new Type[] {}); if (ctorInfo == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className)); } newListener = (TraceListener)(SecurityUtils.ConstructorInfoInvoke(ctorInfo, new object[] { })); } // create a listener with a one-string constructor else { ConstructorInfo ctorInfo = t.GetConstructor(new Type[] { typeof(string) }); if (ctorInfo == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className)); } newListener = (TraceListener)(SecurityUtils.ConstructorInfoInvoke(ctorInfo, new object[] { initializeData })); } if (name != null) { newListener.Name = name; } } // we already verified above that we only have "add", "remove", or "clear", so we can // switch on the first char here for perf. switch (op[0]) { case 'a': if (newListener == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, name)); } Trace.Listeners.Add(newListener); break; case 'r': if (newListener == null) { // no type specified, we'll have to delete by name // if no name is specified we can't do anything if (name == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_remove_with_null)); } Trace.Listeners.Remove(name); } else { // remove by listener Trace.Listeners.Remove(newListener); } break; case 'c': Trace.Listeners.Clear(); break; default: HandlerBase.ThrowUnrecognizedElement(listenersChild); break; } } }
private void AddTraceListener(IDictionary d, XmlNode child, XmlAttributeCollection attributes, TraceListenerCollection listeners) { string name = GetAttribute(attributes, "name", true, child); string type = null; #if CONFIGURATION_DEP type = GetAttribute(attributes, "type", false, child); if (type == null) { // indicated by name. TraceListener shared = GetSharedListeners(d) [name]; if (shared == null) { throw new ConfigurationException(String.Format("Shared trace listener {0} does not exist.", name)); } if (attributes.Count != 0) { throw new ConfigurationErrorsException(string.Format( "Listener '{0}' references a shared " + "listener and can only have a 'Name' " + "attribute.", name)); } listeners.Add(shared, configValues); return; } #else type = GetAttribute(attributes, "type", true, child); #endif Type t = Type.GetType(type); if (t == null) { throw new ConfigurationException(string.Format("Invalid Type Specified: {0}", type)); } object[] args; Type[] types; string initializeData = GetAttribute(attributes, "initializeData", false, child); if (initializeData != null) { args = new object[] { initializeData }; types = new Type[] { typeof(string) }; } else { args = null; types = Type.EmptyTypes; } BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; if (t.Assembly == GetType().Assembly) { flags |= BindingFlags.NonPublic; } ConstructorInfo ctor = t.GetConstructor(flags, null, types, null); if (ctor == null) { throw new ConfigurationException("Couldn't find constructor for class " + type); } TraceListener l = (TraceListener)ctor.Invoke(args); l.Name = name; #if CONFIGURATION_DEP string trace = GetAttribute(attributes, "traceOutputOptions", false, child); if (trace != null) { if (trace != trace.Trim()) { throw new ConfigurationErrorsException(string.Format( "Invalid value '{0}' for 'traceOutputOptions'.", trace), child); } TraceOptions trace_options; try { trace_options = (TraceOptions)Enum.Parse( typeof(TraceOptions), trace); } catch (ArgumentException) { throw new ConfigurationErrorsException(string.Format( "Invalid value '{0}' for 'traceOutputOptions'.", trace), child); } l.TraceOutputOptions = trace_options; } string [] supported_attributes = l.GetSupportedAttributes(); if (supported_attributes != null) { for (int i = 0; i < supported_attributes.Length; i++) { string key = supported_attributes [i]; string value = GetAttribute(attributes, key, false, child); if (value != null) { l.Attributes.Add(key, value); } } } #endif listeners.Add(l, configValues); }
public void Insert(int index, TraceListener listener) { InitializeListener(listener); listeners.Insert(index, listener); }
/// <devdoc> /// <para>Checks whether the list contains the specified /// listener.</para> /// </devdoc> public bool Contains(TraceListener listener) { return(((IList)this).Contains(listener)); }
public int Add(TraceListener listener) { return(default(int)); }
public void Remove(TraceListener listener) { listeners.Remove(listener); }
internal void Add(TraceListener listener, TraceImplSettings settings) { listener.IndentLevel = settings.IndentLevel; listener.IndentSize = settings.IndentSize; listeners.Add(listener); }
private static void HandleListeners(Hashtable config, XmlNode listenersNode, object context) { HandlerBase.CheckForUnrecognizedAttributes(listenersNode); foreach (XmlNode node in listenersNode.ChildNodes) { string str5; if (HandlerBase.IsIgnorableAlsoCheckForNonElement(node)) { continue; } string val = null; string str2 = null; string str3 = null; string name = node.Name; if (((str5 = name) == null) || (((str5 != "add") && (str5 != "remove")) && (str5 != "clear"))) { HandlerBase.ThrowUnrecognizedElement(node); } HandlerBase.GetAndRemoveStringAttribute(node, "name", ref val); HandlerBase.GetAndRemoveStringAttribute(node, "type", ref str2); HandlerBase.GetAndRemoveStringAttribute(node, "initializeData", ref str3); HandlerBase.CheckForUnrecognizedAttributes(node); HandlerBase.CheckForChildNodes(node); TraceListener listener = null; if (str2 != null) { Type c = Type.GetType(str2); if (c == null) { throw new ConfigurationErrorsException(System.SR.GetString("Could_not_find_type", new object[] { str2 })); } if (!typeof(TraceListener).IsAssignableFrom(c)) { throw new ConfigurationErrorsException(System.SR.GetString("Type_isnt_tracelistener", new object[] { str2 })); } if (str3 == null) { ConstructorInfo constructor = c.GetConstructor(new Type[0]); if (constructor == null) { throw new ConfigurationErrorsException(System.SR.GetString("Could_not_get_constructor", new object[] { str2 })); } listener = (TraceListener)SecurityUtils.ConstructorInfoInvoke(constructor, new object[0]); } else { ConstructorInfo ctor = c.GetConstructor(new Type[] { typeof(string) }); if (ctor == null) { throw new ConfigurationErrorsException(System.SR.GetString("Could_not_get_constructor", new object[] { str2 })); } listener = (TraceListener)SecurityUtils.ConstructorInfoInvoke(ctor, new object[] { str3 }); } if (val != null) { listener.Name = val; } } switch (name[0]) { case 'a': if (listener == null) { throw new ConfigurationErrorsException(System.SR.GetString("Could_not_create_listener", new object[] { val })); } break; case 'c': { Trace.Listeners.Clear(); continue; } case 'r': { if (listener != null) { goto Label_0258; } if (val == null) { throw new ConfigurationErrorsException(System.SR.GetString("Cannot_remove_with_null")); } Trace.Listeners.Remove(val); continue; } default: goto Label_0272; } Trace.Listeners.Add(listener); continue; Label_0258: Trace.Listeners.Remove(listener); continue; Label_0272: HandlerBase.ThrowUnrecognizedElement(node); } }
public int Add(System.Diagnostics.TraceListener listener) { throw null; }
internal TraceListener RefreshRuntimeObject(TraceListener listener) { _runtimeObject = null; try { string className = TypeName; if (String.IsNullOrEmpty(className)) { // Look it up in SharedListeners and ask the sharedListener to refresh. Debug.Assert(_allowReferences, "_allowReferences must be true if type name is null"); if (_attributes != null || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || TraceOutputOptions != TraceOptions.None || !String.IsNullOrEmpty(InitData)) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_listener_cant_have_properties, Name)); } if (DiagnosticsConfiguration.SharedListeners == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name)); } ListenerElement sharedListener = DiagnosticsConfiguration.SharedListeners[Name]; if (sharedListener == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name)); } else { _runtimeObject = sharedListener.RefreshRuntimeObject(listener); return((TraceListener)_runtimeObject); } } else { // We're the element with the type and initializeData info. First see if those two are the same as they were. // If not, create a whole new object, otherwise, just update the other properties. if (Type.GetType(className) != listener.GetType() || InitData != listener.initializeData) { // type or initdata changed return(GetRuntimeObject()); } else { listener.SetAttributes(Attributes); listener.TraceOutputOptions = TraceOutputOptions; if (listener.Filter != null) { if (ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.Inherited) { listener.Filter = Filter.RefreshRuntimeObject(listener.Filter); } else { listener.Filter = null; } } _runtimeObject = listener; return(listener); } } } catch (ArgumentException e) { throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, Name), e); } }
/// <include file='doc\TraceListeners.uex' path='docs/doc[@for="TraceListenerCollection.Add"]/*' /> /// <devdoc> /// <para>Adds a <see cref='System.Diagnostics.TraceListener'/> to the list.</para> /// </devdoc> public int Add(TraceListener listener) { InitializeListener(listener); return(((IList)this).Add(listener)); }
//--------------------------------------------------------------------- public static SysDiag.TraceListener[] Copy(SysDiag.TraceListenerCollection listeners) { SysDiag.TraceListener[] array = new SysDiag.TraceListener[listeners.Count]; listeners.CopyTo(array, 0); return(array); }
internal void InitializeListener(TraceListener listener) { listener.IndentSize = TraceInternal.IndentSize; listener.IndentLevel = TraceInternal.IndentLevel; }
public int IndexOf(TraceListener listener) { throw new NotImplementedException(); }
internal void Refresh() { if (!_initCalled) { Initialize(); return; } SourceElementsCollection sources = DiagnosticsConfiguration.Sources; if (sources != null) { SourceElement sourceElement = sources[Name]; if (sourceElement != null) { // first check if the type changed if ((String.IsNullOrEmpty(sourceElement.SwitchType) && internalSwitch.GetType() != typeof(SourceSwitch)) || (sourceElement.SwitchType != internalSwitch.GetType().AssemblyQualifiedName)) { if (!String.IsNullOrEmpty(sourceElement.SwitchName)) { CreateSwitch(sourceElement.SwitchType, sourceElement.SwitchName); } else { CreateSwitch(sourceElement.SwitchType, Name); if (!String.IsNullOrEmpty(sourceElement.SwitchValue)) { internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue); } } } else if (!String.IsNullOrEmpty(sourceElement.SwitchName)) { // create a new switch if the name changed, otherwise just refresh. if (sourceElement.SwitchName != internalSwitch.DisplayName) { CreateSwitch(sourceElement.SwitchType, sourceElement.SwitchName); } else { internalSwitch.Refresh(); } } else { // the switchValue changed. Just update our internalSwitch. if (!String.IsNullOrEmpty(sourceElement.SwitchValue)) { internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue); } else { internalSwitch.Level = SourceLevels.Off; } } TraceListenerCollection newListenerCollection = new TraceListenerCollection(); foreach (ListenerElement listenerElement in sourceElement.Listeners) { TraceListener listener = listeners[listenerElement.Name]; if (listener != null) { newListenerCollection.Add(listenerElement.RefreshRuntimeObject(listener)); } else { newListenerCollection.Add(listenerElement.GetRuntimeObject()); } } TraceUtils.VerifyAttributes(sourceElement.Attributes, GetSupportedAttributes(), this); attributes = new StringDictionary(); attributes.contents = sourceElement.Attributes; listeners = newListenerCollection; } else { // there was no config, so clear whatever we have. internalSwitch.Level = switchLevel; listeners.Clear(); attributes = null; } } }
public void Insert(int index, TraceListener listener) { throw new NotImplementedException(); }
/// <devdoc> /// <para> /// Removes the specified instance of the <see cref='System.Diagnostics.TraceListener'/> class from the list. /// </para> /// </devdoc> public void Remove(TraceListener listener) { ((IList)this).Remove(listener); }
public bool Contains(TraceListener listener) { throw new NotImplementedException(); }