Пример #1
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static SysLog()
        {
            var config = new Config("Diagnostics.SysLog");

            SysLog.CacheInformation = config.Get("CacheInformation", false);
            SysLog.CacheWarnings    = config.Get("CacheWarnings", true);
            SysLog.CacheErrors      = config.Get("CacheErrors", true);
            SysLog.CacheExceptions  = config.Get("CacheExceptions", true);
            SysLog.CacheSecurity    = config.Get("CacheSecurity", false);
            SysLog.CacheDebug       = config.Get("CacheDebug", false);

            cacheTime = config.Get("CacheTime", cacheTime);
            AsyncTimer.BeginTimer(TimeSpan.FromMinutes(1), onTimer, null);
        }
Пример #2
0
        /// <summary>
        /// Handles the background cache maintenance.
        /// </summary>
        /// <param name="ar">The <see cref="IAsyncResult" />.</param>
        private static void OnCacheTimer(IAsyncResult ar)
        {
            AsyncTimer.EndTimer(ar);

            try
            {
                lock (cache)
                {
                    // Handle expired cache entries

                    List <MD5Key> delList = new List <MD5Key>();
                    DateTime      now     = SysTime.Now;

                    foreach (MD5Key key in cache.Keys)
                    {
                        var entry = cache[key];

                        if (entry.TTD <= now)
                        {
                            // Expired

                            delList.Add(key);
                            LogCachedEntry(entry);
                        }
                    }

                    foreach (MD5Key key in delList)
                    {
                        cache.Remove(key);
                    }
                }
            }
            finally
            {
                AsyncTimer.BeginTimer(TimeSpan.FromMinutes(1), onTimer, null);
            }
        }