internal void ForceRemoveBuggyClient(IActivityMonitorClient client) { Debug.Assert(client != null && _clients.Contains(client)); IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient; if (bound != null) { try { bound.SetMonitor(null, true); } catch (Exception ex) { ActivityMonitor.CriticalErrorCollector.Add(ex, "While removing the buggy client."); } } if (_clients.Length == 1) { _clients = Util.Array.Empty <IActivityMonitorClient>(); } else { int idx = Array.IndexOf(_clients, client); var newArray = new IActivityMonitorClient[_clients.Length - 1]; Array.Copy(_clients, 0, newArray, 0, idx); Array.Copy(_clients, idx + 1, newArray, idx, newArray.Length - idx); _clients = newArray; } }
/// <summary> /// Unregisters the given <see cref="IActivityMonitorClient"/> from the <see cref="Clients"/> list. /// Silently ignores unregistered client. /// </summary> /// <param name="client">An <see cref="IActivityMonitorClient"/> implementation.</param> /// <returns>The unregistered client or null if it has not been found.</returns> public IActivityMonitorClient UnregisterClient(IActivityMonitorClient client) { if (client == null) { throw new ArgumentNullException("client"); } using (_monitor.ReentrancyAndConcurrencyLock()) { int idx; if ((idx = Array.IndexOf(_clients, client)) >= 0) { LogFilter filter = LogFilter.Undefined; IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient; if (bound != null) { filter = bound.MinimalFilter; bound.SetMonitor(null, false); } var newArray = new IActivityMonitorClient[_clients.Length - 1]; Array.Copy(_clients, 0, newArray, 0, idx); Array.Copy(_clients, idx + 1, newArray, idx, newArray.Length - idx); _clients = newArray; if (filter != LogFilter.Undefined) { _monitor.OnClientMinimalFilterChanged(filter, LogFilter.Undefined); } return(client); } return(null); } }
/// <summary> /// Registers an <see cref="IActivityMonitorClient"/> to the <see cref="Clients"/> list. /// Duplicate IActivityMonitorClient are silently ignored. /// </summary> /// <param name="client">An <see cref="IActivityMonitorClient"/> implementation.</param> /// <param name="added">True if the client has been added, false if it was already registered.</param> /// <returns>The registered client.</returns> public IActivityMonitorClient RegisterClient(IActivityMonitorClient client, out bool added) { if (client == null) { throw new ArgumentNullException("client"); } using (_monitor.ReentrancyAndConcurrencyLock()) { added = false; return(DoRegisterClient(client, ref added)); } }
static SystemActivityMonitor() { AppSettingsKey = "CK.Core.SystemActivityMonitor.RootLogPath"; SubDirectoryName = "CriticalErrors/"; _client = new SysClient(); _lockedClient = new SysLockedClient(); _appSettingslogPath = AppSettings.Default[AppSettingsKey]; if (_appSettingslogPath != null) { _appSettingslogPath = Environment.ExpandEnvironmentVariables(_appSettingslogPath); } _activityMonitorErrorTracked = 1; ActivityMonitor.CriticalErrorCollector.OnErrorFromBackgroundThreads += OnTrackActivityMonitorLoggingError; }
private IActivityMonitorClient DoRegisterClient(IActivityMonitorClient client, ref bool forceAdded) { if ((forceAdded |= (Array.IndexOf(_clients, client) < 0))) { IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient; if (bound != null) { // Calling SetMonitor before adding it to the client first // enables the monitor to initialize itself before being solicited. // And if SetMonitor method calls InitializeTopicAndAutoTags, it does not // receive a "stupid" OnTopic/AutoTagsChanged. bound.SetMonitor(_monitor, false); } var newArray = new IActivityMonitorClient[_clients.Length + 1]; Array.Copy(_clients, 0, newArray, 1, _clients.Length); newArray[0] = client; _clients = newArray; if (bound != null) { _monitor.OnClientMinimalFilterChanged(LogFilter.Undefined, bound.MinimalFilter); } } return(client); }
/// <summary> /// Registers an <see cref="IActivityMonitorClient"/> to the <see cref="IActivityMonitorOutput.Clients">Clients</see> list. /// Duplicates IActivityMonitorClient are silently ignored. /// </summary> /// <param name="this">This <see cref="IActivityMonitorOutput"/> object.</param> /// <param name="client">An <see cref="IActivityMonitorClient"/> implementation.</param> /// <returns>The registered client.</returns> public static IActivityMonitorClient RegisterClient(this IActivityMonitorOutput @this, IActivityMonitorClient client) { bool added; return(@this.RegisterClient(client, out added)); }
static SystemActivityMonitor() { AppSettingsKey = "CK.Core.SystemActivityMonitor.RootLogPath"; SubDirectoryName = "CriticalErrors/"; _client = new SysClient(); _lockedClient = new SysLockedClient(); _appSettingslogPath = AppSettings.Default[AppSettingsKey]; if( _appSettingslogPath != null ) _appSettingslogPath = Environment.ExpandEnvironmentVariables( _appSettingslogPath ); _activityMonitorErrorTracked = 1; ActivityMonitor.CriticalErrorCollector.OnErrorFromBackgroundThreads += OnTrackActivityMonitorLoggingError; }