// ****************************************************************** // * * // * ILogThread Interface * // * * // ****************************************************************** /// <summary> /// Starts the logger thread /// </summary> /// <param name="sessionGuid"> /// A Guid that uniquely indentifies the current logging session /// </param> /// <param name="sessionFolderFullName"> /// A string that holds the current session folder (i.e. location where /// current log(s) will be persisted) including process context name /// </param> /// <param name="sessionResourceFolderFullName"> /// A string that specifies the current session resource folder (i.e. location /// inside session folder where resource files will be persisted) /// </param> /// <param name="config"> /// An ILogConfig reference.<br/> /// Note: this instance wil be cloned to ensure that configuration changes after /// thread has been started will not affect current execution. /// </param> public virtual void Start( Guid sessionGuid, string sessionFolderFullName, string sessionResourceFolderFullName, ILogConfig config) { // Check if not already running if (m_isRunningFlag) { throw new InvalidOperationException("Cannot start a running LogThread"); } // Turn running flag on m_isRunningFlag = true; m_sessionGuid = sessionGuid; m_sessionConfig = config.Clone(); m_sessionFolderFullName = sessionFolderFullName; m_sessionResourceFolderFullName = sessionResourceFolderFullName; // Ensure message queue is empty m_messageQueue.Clear(); // Ensure cache of streamers is also empty m_streamers.Clear(); // Create a new logging thread and start it m_thread = new Thread(new ThreadStart(StartThread)) { Name = string.Format("Log Thread - {0}", sessionGuid) }; m_thread.Start(); // Start auto-flush timer? if (m_sessionConfig.AutoFlushStartupTime > 0 && m_sessionConfig.AutoFlushPeriodicTime > 0) { m_autoFlushTimer.Change( m_sessionConfig.AutoFlushStartupTime, m_sessionConfig.AutoFlushPeriodicTime); } }
// ****************************************************************** // * * // * Protected Methods * // * * // ****************************************************************** /// <summary> /// Creates and initializes a new set of ILogStreamer instances /// </summary> /// <param name="message"> /// A LogMessage instance for which a new set of streamer instances must be created /// </param> /// <returns> /// An array that holds a set of new ILogStreamer instances /// </returns> protected ILogStreamer[] CreateAndInitializeStreamers(LogMessage message) { // Resolve configuration entry for this log LogConfigDefaultEntry entry = m_sessionConfig.DefaultEntry; LogConfigEntry configEntry; if (m_sessionConfig.TryGetEntryById(message.ConfigEntryId, out configEntry)) { entry = configEntry; } // Create streamer instances ILogStreamer[] streamers; IParameterDictionary[] parameters; entry.CreateStreamers(out streamers, out parameters); // Count concurrent streamer types var dicConcurrentTypesCount = new Dictionary <Type, int>(); var lstConcurrentTypesIndex = new List <int>(); for (int i = 0; i < streamers.Length; i++) { // Did we already encountered this type? int count; var type = streamers[i].GetType(); if (dicConcurrentTypesCount.TryGetValue(type, out count)) { dicConcurrentTypesCount[type] = count + 1; lstConcurrentTypesIndex.Add(count + 1); } else { dicConcurrentTypesCount[type] = 1; lstConcurrentTypesIndex.Add(1); } } // Modify config in case we are working with stream for logmanager // This is a special case where we DO NOT want to apply cleanup. // We want to ensure that all messages are kept to enable reading! var config = m_sessionConfig; if (message.LogName == LogManager.LOGNAME_LOGMANAGER) { // Create copy of config and config = m_sessionConfig.Clone(); config.CleanupMessages = -1; } // Initialize streamers for (int i = 0; i < streamers.Length; i++) { streamers[i].Init(new LogStreamerInitArgs( m_sessionGuid, m_sessionFolderFullName, m_sessionResourceFolderFullName, config, parameters[i], message.LogName, dicConcurrentTypesCount[streamers[i].GetType()], lstConcurrentTypesIndex[i])); } // Return references return(streamers); }
public void ApplyConfiguration( ILogConfig c ) { _logConfig = c.Clone(); }