コード例 #1
0
ファイル: Logger.cs プロジェクト: Yortw/ScribeSharp
        /// <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;
        }
コード例 #2
0
ファイル: LoggedJob.cs プロジェクト: Yortw/ScribeSharp
        public void Initialize(ILogger logger, string jobName, string jobId, IEnumerable <KeyValuePair <string, object> > properties, ILoggedJobPool parentPool, TimeSpan maxExpectedDuration)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (jobName == null)
            {
                throw new ArgumentNullException(nameof(jobName));
            }
            if (String.IsNullOrWhiteSpace(jobName))
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeEmptyOrWhitespace, jobName), nameof(jobName));
            }

            if (String.IsNullOrWhiteSpace(jobId))
            {
                jobId = Guid.NewGuid().ToString();
            }

#if CONTRACTS_ONLY
            BaitExceptionHelper.Throw();
#else
            _ParentPool          = parentPool;
            _Stopwatch           = new System.Diagnostics.Stopwatch();
            _Logger              = logger;
            _JobId               = jobId ?? Guid.NewGuid().ToString();
            _JobName             = jobName;
            _MaxExpectedDuration = maxExpectedDuration;
            _Properties          = GetExtendedProperties(properties,
                                                         new KeyValuePair <string, object>(Properties.Resources.JobNamePropertyName, jobName),
                                                         new KeyValuePair <string, object>(Properties.Resources.JobIdPropertyName, jobId)
                                                         ).ToArray();

            _Logger.WriteEvent(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.JobStartedEventMessage, jobName, jobId),
                               eventSeverity: LogEventSeverity.Information,
                               eventType: LogEventType.Start,
                               properties: _Properties
                               );

            _Stopwatch.Start();
#endif
        }
コード例 #3
0
ファイル: LoggedJob.cs プロジェクト: Yortw/ScribeSharp
 public void Initialize(ILogger logger, string jobName, string jobId, IEnumerable <KeyValuePair <string, object> > properties, ILoggedJobPool parentPool)
 {
     Initialize(logger, jobName, jobId, properties, parentPool, TimeSpan.Zero);
 }