예제 #1
0
 /// <summary>
 /// Is called every time a log is removed from the collection.
 /// </summary>
 /// <param name="log">The log removed.</param>
 private static void OnLogRemoved(AppLog log)
 {
     if (LogRemoved != null)
         LogRemoved(log);
 }
예제 #2
0
        /// <summary>
        /// Static constructor. Reads the name of the default log from the application 
        /// settings and assigns it to a static property.
        /// </summary>
        static AppLog()
        {
            string setting = ConfigurationManager.AppSettings["logs"];
            string defaultLog = "General";

            // Take the first log name from the settings as the default
            if (!string.IsNullOrWhiteSpace(setting))
            {
                string[] logs = setting.Split(';');
                defaultLog = logs != null && logs.Length > 0 ? logs[0] : "General";
            }

            // Use the default value, or the first value retrieved from the settings
            Default = GetLog(defaultLog);
        }
예제 #3
0
        /// <summary>
        /// Returns the application log with the given name. Creates a new
        /// log instance, if it does not exist yet.
        /// </summary>
        /// <param name="name">The name of the log to retrieve/create.</param>
        /// <returns>A log instance with the given name.</returns>
        public static AppLog GetLog(string name)
        {
            AppLog log = null;
            Logs.TryGetValue(name, out log);

            if (log == null)
            {
                log = new AppLog(name);
                Logs.Add(name, log);

                AppLog.OnLogAdded(log);
            }

            return log;
        }