/// <summary> /// Creates the Logger object from settings in the Loggers.config. /// </summary> /// <param name="name"><c>String</c> that specifies the name of the <c>Logger</c> to lookup.</param> /// <returns><c>Logger</c> name</returns> private static Logger FillLogger( string name) { Logger log = null; XmlConfiguration config = new XmlConfiguration(); try { // get the path to the loggers.config file from web.config string loggersConfigPath = ConfigurationSettings.AppSettings["rootPath"]; // Load XmlConfiguration to get settings for this logger config.Load(loggersConfigPath + ConfigurationSettings.AppSettings["loggersConfigPath"]); //config.Load(new XmlTextReader(loggersConfigPath + ConfigurationSettings.AppSettings["loggersConfigPath"])); //config.Load(new XmlTextReader("http://fpwssdev1/PandaDen/XSLT%20Templates/loggers.config")); log = new Logger(name); // If there is configuration information, proceed, else return a new empty Logger if (config != null) { // this code will read the queue process time from a "settings" section of the config file: // <settings> // <!-- the time interval at which the log queue--> // <setting name="queSettings" queCheckTime="10000" /> // </settings> //XmlConfiguration queSettings = config.GetConfig("settings", QUEUE_SETTINGS_CONFIG_NAME); //if (queSettings != null) { // try { // NameValueCollection queAttr = queSettings.GetAttributes("./*[1]"); // int period = int.Parse(queAttr[QUEUE_SETTINGS_CHECK_TIME_ATTR]); // log.queTimer.Change(period, period); // } catch {} //} // get the logger's config settings config = config.GetConfig("loggers", name); NameValueCollection loggerAttrs = config.GetAttributes("./*[1]"); // Loop log collection attributes to dynamically set the log object's properties for (int i = 0; i < loggerAttrs.Count; i++) { string attrName = loggerAttrs.GetKey(i); string attrValue = loggerAttrs.Get(i); // if the attribute is the queue check time attribute, get the value // and update the queTimer with the new value (in milliseconds) if (attrName == QUEUE_SETTINGS_CHECK_TIME_ATTR) { try { int period = int.Parse(attrValue); log.queTimer.Change(period, period); } catch {} } else { // set the corresponding attribute of the object SetObjectAttribute(log, attrName, attrValue); } } // Add Filter and all Handler objects log.Filter = FillFilter(config); log.FillHandlers(config); // Logger objects must have at least one handler if (log.handlers.Count == 0) { log = null; } } } catch (Exception e) { log = null; } return log; }
/// <summary> /// Creates a filter to apply the the Logger from the corresponding section in Loggers.config. /// </summary> /// <param name="name"><c>String</c> that specifies the name of the <c>Logger</c> to lookup.</param> /// <returns><c>ILogFilter</c> set for Logger from config file.</returns> private static ILogFilter FillFilter( XmlConfiguration config) { ILogFilter filter = null; NameValueCollection filterColl = null; string filterClass = null; config = config.GetConfig("logger", "filter"); // Create the Filter object try { filterColl = config.GetAttributes("filter"); filterClass = filterColl["class"]; filter = (ILogFilter) Activator.CreateInstance(Type.GetType(filterClass)); } catch (Exception e) { // System.MissingMethodException } return filter; }