Beispiel #1
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="policy">A <see cref="LogPolicy"/> instance used to configure this logger.</param>
        /// <remarks>
        /// <para>The <paramref name="policy"/> should not be changed after being provided to the logger. Values from the policy are cached or copied before use and will not change even if the policy is updated after the logger is constructed.</para>
        /// </remarks>
        public Logger(LogPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }
            if (policy.LogWriter == null)
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeNull, "policy.LogWriter"), nameof(policy));
            }

            _ErrorHandler = policy.ErrorHandler ?? SuppressingErrorHandler.DefaultInstance;
            _EntryPool    = new LogEventPool(policy.LogEventPoolCapacity);
            _JobPool      = new LoggedJobPool(policy.JobPoolCapacity);

            _LogWriter                = policy.LogWriter;
            _LogClock                 = policy.Clock ?? new CachingClock(new LocalSystemClock(), TimeSpan.FromTicks(16));
            _Filter                   = policy.Filter;
            _FirstChanceFilter        = policy.FirstChanceFilter;
            _RendererMap              = policy.TypeRendererMap;
            _Source                   = policy.Source;
            _DefaultExceptionRenderer = policy.DefaultExceptionRenderer;

            if (policy.ContextProviders != null)
            {
                _ContextProviders = (policy.ContextProviders as ILogEventContextProvider[]) ?? policy.ContextProviders.ToArray();
            }

            _IsEnabled = true;
        }
Beispiel #2
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="innerClock">Another <see cref="ILogClock"/> implementation to actually get the current time from when required.</param>
        /// <param name="cacheInterval">The interval to cache the time for once it has been requested. Subsequent requests after that time will be cached.</param>
        public CachingClock(ILogClock innerClock, TimeSpan cacheInterval)
        {
            if (innerClock == null)
            {
                throw new ArgumentNullException(nameof(innerClock));
            }
            if (cacheInterval.Ticks > Int32.MaxValue)
            {
                throw new ArgumentOutOfRangeException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.ArgumentOutOfRangeMessage, "cacheInterval.Ticks", 1, Int32.MaxValue));
            }

            _InnerClock           = innerClock;
            _CacheIntervalTicks   = Convert.ToInt32(cacheInterval.Milliseconds);           //Environment.TickCount is actually milliseconds, not 'ticks'
            _CachedTime           = innerClock.Now;
            _LastCheckedTimeTicks = Environment.TickCount;
        }
Beispiel #3
0
        // ILogWriter logWriter, IEnumerable<ILogEventContextProvider> contextProviders, ILogClock logClock
        public Logger(LogPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }
            if (policy.LogWriter == null)
            {
                throw new ArgumentException("policy.LogWriter cannot be null", nameof(policy));
            }

            _EntryPool = new LogEventPool();
            _LogWriter = policy.LogWriter;
            _LogClock  = policy.Clock;
            _Filter    = policy.Filter;

            if (policy.ContextProviders != null)
            {
                _ContextProviders = (policy.ContextProviders as ILogEventContextProvider[]) ?? policy.ContextProviders.ToArray();
            }

            _IsEnabled = true;
        }