private void NoConfigInit() { internalSwitch = new SourceSwitch(sourceName, switchLevel.ToString()); listeners = new TraceListenerCollection(); listeners.Add(new DefaultTraceListener()); attributes = null; }
public TraceListenerCollection GetRuntimeObject() { TraceListenerCollection listeners = new TraceListenerCollection(); bool _isDemanded = false; foreach (ListenerElement element in this) { // At some point, we need to pull out adding/removing the 'default' DefaultTraceListener // code from here in favor of adding/not-adding after we load the config (in TraceSource // and in static Trace) if (!_isDemanded && !element._isAddedByDefault) { // Do a full damand; This will disable partially trusted code from hooking up listeners new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); _isDemanded = true; } listeners.Add(element.GetRuntimeObject()); } return(listeners); }
private void TraceConfiguration() { try { //delete the old log file string logPath = Path.Combine(PathHelper.ApplicationPath, "ReflectionStudio.exe.log"); if (File.Exists(logPath)) { File.Delete(logPath); } if (ReflectionStudio.Properties.Settings.Default.UseTraceListener) { //configure the trace System.Diagnostics.Trace.AutoFlush = true; System.Diagnostics.Trace.IndentSize = 2; //configure the text listenner System.Diagnostics.TraceListenerCollection listeners = System.Diagnostics.Trace.Listeners; listeners.Add(new System.Diagnostics.TextWriterTraceListener(logPath, "LOG")); } } catch (Exception error) { Tracer.Error("Reflection Studio.TraceConfiguration", error); } }
public TraceImplSettings() { Listeners.Add(new DefaultTraceListener() { IndentSize = this.IndentSize }); }
private void AddTraceListener(IDictionary d, string name, string type, string initializeData, TraceListenerCollection listeners) { #if NET_2_0 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)); } listeners.Add(shared); return; } #endif Type t = Type.GetType(type); if (t == null) { throw new ConfigurationException(string.Format("Invalid Type Specified: {0}", type)); } object[] args; Type[] types; if (initializeData != null) { args = new object[] { initializeData }; types = new Type[] { typeof(string) }; } else { args = null; types = new Type[0]; } System.Reflection.ConstructorInfo ctor = t.GetConstructor(types); if (ctor == null) { throw new ConfigurationException("Couldn't find constructor for class " + type); } TraceListener l = (TraceListener)ctor.Invoke(args); l.Name = name; listeners.Add(l); }
// Make sure that the trace configuration is loaded. internal static void Initialize() { // Bail out if already initialized, or called recursively. if (initialized) { return; } initialized = true; // Create the default trace listener. DefaultTraceListener defListener = new DefaultTraceListener(); // Create the initial listeners collection. listeners = new TraceListenerCollection(); listeners.Add(defListener); // Get the diagnostics configuration options. Hashtable options = (Hashtable) ConfigurationSettings.GetConfig ("system.diagnostics", new DiagnosticsConfigurationHandler()); if (options == null) { options = new Hashtable(); } // Process the options for the default trace listener. Object value = options["assertuienabled"]; if (value != null) { defListener.AssertUiEnabled = (bool)value; } value = options["logfilename"]; if (value != null) { defListener.LogFileName = (String)value; } // Process the trace options. value = options["autoflush"]; if (value != null) { autoFlush = (bool)value; } value = options["indentsize"]; if (value != null) { indentSize = (int)value; } switches = (Hashtable)(options["switches"]); }
// Make sure that the trace configuration is loaded. internal static void Initialize() { // Bail out if already initialized, or called recursively. if(initialized) { return; } initialized = true; // Create the default trace listener. DefaultTraceListener defListener = new DefaultTraceListener(); // Create the initial listeners collection. listeners = new TraceListenerCollection(); listeners.Add(defListener); // Get the diagnostics configuration options. Hashtable options = (Hashtable) ConfigurationSettings.GetConfig ("system.diagnostics", new DiagnosticsConfigurationHandler()); if(options == null) { options = new Hashtable(); } // Process the options for the default trace listener. Object value = options["assertuienabled"]; if(value != null) { defListener.AssertUiEnabled = (bool)value; } value = options["logfilename"]; if(value != null) { defListener.LogFileName = (String)value; } // Process the trace options. value = options["autoflush"]; if(value != null) { autoFlush = (bool)value; } value = options["indentsize"]; if(value != null) { indentSize = (int)value; } switches = (Hashtable)(options["switches"]); }
public TraceListenerCollection GetRuntimeObject() { TraceListenerCollection listeners = new TraceListenerCollection(); bool flag = false; foreach (ListenerElement element in this) { if (!flag && !element._isAddedByDefault) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); flag = true; } listeners.Add(element.GetRuntimeObject()); } return listeners; }
/// <summary> /// Registers trace listeners to be used by the application. /// Generally web.config is used to do this, but there are special cases. /// </summary> /// <param name="traceListenerCollection"> /// The trace Listener Collection to register trace listeners at. /// </param> public static void RegisterTraceListeners(TraceListenerCollection traceListenerCollection) { // This replaces web.config setting: configuration\system.diagnostics\trace\listeners\add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics" // This is done because DiagnosticMonitorTraceListener class throws exception when not running in azure/devfabric. if (RoleEnvironment.IsAvailable) { // See 'diagnostics.wadcfg' file. It contains all configurations of the DiagnosticMonitor. // It is not needed to configure nor start the DiagnosticMonitor manually in code. // It will be started automatically and will use settings in the 'diagnostics.wadcfg' file. // All we need to do is to add the trace listener. // reference: http://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/ // google: https://www.google.com/search?q=diagnostics.wadcfg traceListenerCollection.Add(new DiagnosticMonitorTraceListener()); } }
public TraceListenerCollection GetRuntimeObject() { TraceListenerCollection listeners = new TraceListenerCollection(); bool flag = false; foreach (ListenerElement element in this) { if (!flag && !element._isAddedByDefault) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); flag = true; } listeners.Add(element.GetRuntimeObject()); } return(listeners); }
public TraceListenerCollection GetRuntimeObject() { TraceListenerCollection listeners = new TraceListenerCollection(); bool _isDemanded = false; foreach(ListenerElement element in this) { // At some point, we need to pull out adding/removing the 'default' DefaultTraceListener // code from here in favor of adding/not-adding after we load the config (in TraceSource // and in static Trace) if (!_isDemanded && !element._isAddedByDefault) { // Do a full damand; This will disable partially trusted code from hooking up listeners new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); _isDemanded = true; } listeners.Add(element.GetRuntimeObject()); } return listeners; }
internal void Refresh() { if (!this._initCalled) { this.Initialize(); } else { SourceElementsCollection sources = DiagnosticsConfiguration.Sources; if (sources != null) { SourceElement element = sources[this.Name]; if (element != null) { if ((string.IsNullOrEmpty(element.SwitchType) && (this.internalSwitch.GetType() != typeof(SourceSwitch))) || (element.SwitchType != this.internalSwitch.GetType().AssemblyQualifiedName)) { if (!string.IsNullOrEmpty(element.SwitchName)) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.CreateSwitch(element.SwitchType, this.Name); if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels) Enum.Parse(typeof(SourceLevels), element.SwitchValue); } } } else if (!string.IsNullOrEmpty(element.SwitchName)) { if (element.SwitchName != this.internalSwitch.DisplayName) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.internalSwitch.Refresh(); } } else if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels) Enum.Parse(typeof(SourceLevels), element.SwitchValue); } else { this.internalSwitch.Level = SourceLevels.Off; } TraceListenerCollection listeners = new TraceListenerCollection(); foreach (ListenerElement element2 in element.Listeners) { TraceListener listener = this.listeners[element2.Name]; if (listener != null) { listeners.Add(element2.RefreshRuntimeObject(listener)); } else { listeners.Add(element2.GetRuntimeObject()); } } TraceUtils.VerifyAttributes(element.Attributes, this.GetSupportedAttributes(), this); this.attributes = new StringDictionary(); this.attributes.ReplaceHashtable(element.Attributes); this.listeners = listeners; } else { this.internalSwitch.Level = this.switchLevel; this.listeners.Clear(); this.attributes = null; } } } }
private void NoConfigInit() { _internalSwitch = new SourceSwitch(_sourceName, _switchLevel.ToString()); _listeners = new TraceListenerCollection(); _listeners.Add(new DefaultTraceListener()); }
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.ReplaceHashtable(sourceElement.Attributes); listeners = newListenerCollection; } else { // there was no config, so clear whatever we have. internalSwitch.Level = switchLevel; listeners.Clear(); attributes = null; } } }
internal void Refresh() { if (!this._initCalled) { this.Initialize(); } else { SourceElementsCollection sources = DiagnosticsConfiguration.Sources; if (sources != null) { SourceElement element = sources[this.Name]; if (element != null) { if ((string.IsNullOrEmpty(element.SwitchType) && (this.internalSwitch.GetType() != typeof(SourceSwitch))) || (element.SwitchType != this.internalSwitch.GetType().AssemblyQualifiedName)) { if (!string.IsNullOrEmpty(element.SwitchName)) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.CreateSwitch(element.SwitchType, this.Name); if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), element.SwitchValue); } } } else if (!string.IsNullOrEmpty(element.SwitchName)) { if (element.SwitchName != this.internalSwitch.DisplayName) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.internalSwitch.Refresh(); } } else if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), element.SwitchValue); } else { this.internalSwitch.Level = SourceLevels.Off; } TraceListenerCollection listeners = new TraceListenerCollection(); foreach (ListenerElement element2 in element.Listeners) { TraceListener listener = this.listeners[element2.Name]; if (listener != null) { listeners.Add(element2.RefreshRuntimeObject(listener)); } else { listeners.Add(element2.GetRuntimeObject()); } } TraceUtils.VerifyAttributes(element.Attributes, this.GetSupportedAttributes(), this); this.attributes = new StringDictionary(); this.attributes.ReplaceHashtable(element.Attributes); this.listeners = listeners; } else { this.internalSwitch.Level = this.switchLevel; this.listeners.Clear(); this.attributes = null; } } } }
public TraceImplSettings() { Listeners.Add(new DefaultTraceListener(), this); }
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); }
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.ReplaceHashtable(sourceElement.Attributes); listeners = newListenerCollection; } else { // there was no config, so clear whatever we have. internalSwitch.Level = switchLevel; listeners.Clear(); attributes = null; } } }
private void AddTraceListener (IDictionary d, XmlNode child, XmlAttributeCollection attributes, TraceListenerCollection listeners) { string name = GetAttribute (attributes, "name", true, child); string type = null; #if NET_2_0 && 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 NET_2_0 && 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 LogModel(TraceListenerCollection traceListenerCollection) { traceListenerCollection.Add(this); }