The fundamental functionality of Logger.
Inheritance: IDisposable
示例#1
0
        /// <summary>
        /// Creates a <see cref="LogEventPublisherInternal"/>.
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="owner">the owner of the log messages.</param>
        /// <param name="publisher">the publisher that is used to raise messages</param>
        /// <param name="logger">the callback for all new messages that are generated.</param>
        /// <param name="stackTraceDepth"></param>
        /// <param name="messagesPerSecond"></param>
        /// <param name="burstLimit"></param>
        internal LogEventPublisherInternal(LogMessageAttributes attributes, LogEventPublisherDetails owner, LogPublisherInternal publisher, LoggerInternal logger, int stackTraceDepth, double messagesPerSecond, int burstLimit)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (publisher == null)
            {
                throw new ArgumentNullException(nameof(publisher));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            m_attributes = attributes;
            var supression = new LogSuppressionEngine(messagesPerSecond, burstLimit);

            m_owner            = owner;
            m_logger           = logger;
            m_stackTraceDepth  = 0;
            m_supressionEngine = supression;
            m_publisher        = publisher;
            m_stackTraceDepth  = stackTraceDepth;
            m_suppressionMessageNextPublishTime = ShortTime.Now;
        }
示例#2
0
 internal LogPublisher(LoggerInternal logger, LogPublisherInternal publisherInstance, MessageClass classification)
 {
     m_logger                       = logger;
     m_publisherInstance            = publisherInstance;
     m_classification               = classification;
     InitialStackMessages           = Logger.GetStackMessages();
     InitialStackTrace              = new LogStackTrace(true, 1, 10);
     MaxDistinctEventPublisherCount = 20;
     m_lookupEventPublishers        = new ConcurrentDictionary <Tuple <LogMessageAttributes, string>, LogEventPublisherInternal>();
 }
        public LogPublisherInternal(LoggerInternal logger, Type type)
        {
            if ((object)type == null)
                throw new ArgumentNullException(nameof(type));
            if (type == null)
                throw new ArgumentNullException(nameof(type));
            if (logger == null)
                throw new ArgumentNullException(nameof(logger));

            Type = type;
            Assembly = type.Assembly;
            TypeData = new PublisherTypeDefinition(type);
            m_logger = logger;
            SubscriptionFilterCollection = new MessageAttributeFilterCollection();
        }
        /// <summary>
        /// Creates a <see cref="LogEventPublisherInternal"/>.
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="owner">the owner of the log messages.</param>
        /// <param name="publisher">the publisher that is used to raise messages</param>
        /// <param name="logger">the callback for all new messages that are generated.</param>
        /// <param name="stackTraceDepth"></param>
        /// <param name="messagesPerSecond"></param>
        /// <param name="burstLimit"></param>
        internal LogEventPublisherInternal(LogMessageAttributes attributes, LogEventPublisherDetails owner, LogPublisherInternal publisher, LoggerInternal logger, int stackTraceDepth, double messagesPerSecond, int burstLimit)
        {
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));
            if (publisher == null)
                throw new ArgumentNullException(nameof(publisher));
            if (logger == null)
                throw new ArgumentNullException(nameof(logger));

            m_attributes = attributes;
            var supression = new LogSuppressionEngine(messagesPerSecond, burstLimit);

            m_owner = owner;
            m_logger = logger;
            m_stackTraceDepth = 0;
            m_supressionEngine = supression;
            m_publisher = publisher;
            m_stackTraceDepth = stackTraceDepth;
            m_suppressionMessageNextPublishTime = ShortTime.Now;
        }
        /// <summary>
        /// Creates a <see cref="LoggerInternal"/>.
        /// </summary>
        public LoggerInternal(out LoggerInternal loggerClass)
        {
            //Needed to set the member variable of Logger. 
            //This is because ScheduleTask will call Logger before Logger's static constructor is completed.
            loggerClass = this;

            m_syncRoot = new object();
            m_typeIndexCache = new Dictionary<Type, LogPublisherInternal>();
            m_allPublishers = new List<LogPublisherInternal>();
            m_subscribers = new List<WeakReference>();
            m_messages = new ConcurrentQueue<Tuple<LogMessage, LogPublisherInternal>>();

            // Since ScheduledTask calls ShutdownHandler, which calls Logger. This initialization method cannot occur
            // until after the Logger static class has finished initializing.
            m_calculateRoutingTable = new ScheduledTask();
            m_calculateRoutingTable.Running += CalculateRoutingTable;
            m_calculateRoutingTable.IgnoreShutdownEvent();
            m_routingTask = new ScheduledTask(ThreadingMode.DedicatedForeground);
            m_routingTask.Running += RoutingTask;
            m_routingTask.IgnoreShutdownEvent();
        }
示例#6
0
        public LogPublisherInternal(LoggerInternal logger, Type type)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            Type     = type;
            Assembly = type.Assembly;
            TypeData = new PublisherTypeDefinition(type);
            m_logger = logger;
            SubscriptionFilterCollection = new MessageAttributeFilterCollection();
        }
示例#7
0
        /// <summary>
        /// Creates a <see cref="LoggerInternal"/>.
        /// </summary>
        public LoggerInternal(out LoggerInternal loggerClass)
        {
            //Needed to set the member variable of Logger.
            //This is because ScheduleTask will call Logger before Logger's static constructor is completed.
            loggerClass = this;

            m_syncRoot       = new object();
            m_typeIndexCache = new Dictionary <Type, LogPublisherInternal>();
            m_allPublishers  = new List <LogPublisherInternal>();
            m_subscribers    = new List <NullableWeakReference>();
            m_messages       = new ConcurrentQueue <Tuple <LogMessage, LogPublisherInternal> >();

            // Since ScheduledTask calls ShutdownHandler, which calls Logger. This initialization method cannot occur
            // until after the Logger static class has finished initializing.
            m_calculateRoutingTable          = new ScheduledTask();
            m_calculateRoutingTable.Running += CalculateRoutingTable;
            m_calculateRoutingTable.IgnoreShutdownEvent();
            m_routingTask          = new ScheduledTask(ThreadingMode.DedicatedForeground);
            m_routingTask.Running += RoutingTask;
            m_routingTask.IgnoreShutdownEvent();
        }
示例#8
0
文件: Logger.cs 项目: sotaria/gsf
        static Logger()
        {
            //Initializes the empty object of StackTraceDetails
            LogStackTrace.Initialize();
            LogStackMessages.Initialize();
            GrowStackDisposal(1);

            s_logger   = new LoggerInternal(out s_logger);
            Console    = new LogSubscriptionConsole();
            FileWriter = new LogSubscriptionFileWriter(1000);

            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;

            Log = CreatePublisher(typeof(Logger), MessageClass.Component);
            Log.InitialStackTrace     = LogStackTrace.Empty;
            EventFirstChanceException = Log.RegisterEvent(MessageLevel.NA, MessageFlags.SystemHealth, "First Chance App Domain Exception", 30, MessageRate.PerSecond(30), 1000);
            EventAppDomainException   = Log.RegisterEvent(MessageLevel.Critical, MessageFlags.SystemHealth, "Unhandled App Domain Exception");
            EventSwallowedException   = Log.RegisterEvent(MessageLevel.Debug, MessageFlags.None, "Exception was Swallowed", 30, MessageRate.PerSecond(30), 1000);

            ShutdownHandler.Initialize();
        }
        internal LogPublisher(LoggerInternal logger, LogPublisherInternal publisherInstance, MessageClass classification)
        {
            m_logger = logger;
            m_publisherInstance = publisherInstance;
            m_classification = classification;
            InitialStackMessages = Logger.GetStackMessages();
            InitialStackTrace = new LogStackTrace(true, 1, 10);
            MaxDistinctEventPublisherCount = 20;
            m_lookupEventPublishers = new ConcurrentDictionary<Tuple<LogMessageAttributes, string>, LogEventPublisherInternal>();

        }
示例#10
0
        static Logger()
        {
            //Initializes the empty object of StackTraceDetails
            LogStackTrace.Initialize();
            LogStackMessages.Initialize();
            GrowStackDisposal(1);

            s_logger = new LoggerInternal(out s_logger);
            Console = new LogSubscriptionConsole();
            FileWriter = new LogSubscriptionFileWriter(1000);

            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Log = CreatePublisher(typeof(Logger), MessageClass.Component);
            Log.InitialStackTrace = LogStackTrace.Empty;
            EventFirstChanceException = Log.RegisterEvent(MessageLevel.NA, MessageFlags.SystemHealth, "First Chance App Domain Exception", 30, MessageRate.PerSecond(30), 1000);
            EventAppDomainException = Log.RegisterEvent(MessageLevel.Critical, MessageFlags.SystemHealth, "Unhandled App Domain Exception");
            EventSwallowedException = Log.RegisterEvent(MessageLevel.Debug, MessageFlags.None, "Exception was Swallowed", 30, MessageRate.PerSecond(30), 1000);

            ShutdownHandler.Initialize();
        }