A publisher of log messages.
InitialStackMessages and InitialStackTrace can be modified so messages that are generated with this instance will have this data appended to the log message. The user can either call one of the Publish overloads to lazily publish a message, or they can register a message with RegisterEvent so calling this message will incur little overhead. If registering an event, the user can check LogEventPublisher.HasSubscribers to determine if the log message can be skipped altogether. Registering events also allows the user to specify the auto-suppression algorithm and the depth of the stack trace that will be recorded on a message being raised.
        static LoadingAdjustedTimestamp()
        {
            Reset();

            Log = Logger.CreatePublisher(typeof(LoadingAdjustedTimestamp), MessageClass.Component);
            LogLoadingClock = Log.RegisterEvent(MessageLevel.Info, MessageFlags.SystemHealth, $"Loading Clock is behind", 0, MessageRate.EveryFewSeconds(1), 1);
            LogSmall = Log.RegisterEvent(MessageLevel.Info, MessageFlags.SystemHealth, $"Short High Load Condition Detected", 0, MessageRate.EveryFewSeconds(10), 5);
            LogMedium = Log.RegisterEvent(MessageLevel.Warning, MessageFlags.SystemHealth, $"Medium High Load Condition Detected", 0, MessageRate.EveryFewSeconds(10), 5);
            LogLarge = Log.RegisterEvent(MessageLevel.Error, MessageFlags.SystemHealth, $"Long High Load Condition Detected", 0, MessageRate.EveryFewSeconds(10), 5);

            LogLoadingClock.ShouldRaiseMessageSupressionNotifications = false;
            LogSmall.ShouldRaiseMessageSupressionNotifications = false;
            LogMedium.ShouldRaiseMessageSupressionNotifications = false;
            LogLarge.ShouldRaiseMessageSupressionNotifications = false;

            MonitorHighThread = new Thread(MonitorHighPriority, short.MaxValue);
            MonitorHighThread.Priority = ThreadPriority.Highest;
            MonitorHighThread.IsBackground = true;
            MonitorHighThread.Start();

            MonitorNormalThread = new Thread(MonitorNormalPriority, short.MaxValue);
            MonitorNormalThread.Priority = ThreadPriority.Normal;
            MonitorNormalThread.IsBackground = true;
            MonitorNormalThread.Start();

            MonitorLowThread = new Thread(MonitorLowPriority, short.MaxValue);
            MonitorLowThread.Priority = ThreadPriority.Lowest;
            MonitorLowThread.IsBackground = true;
            MonitorLowThread.Start();
        }
Пример #2
0
 private static void Error1(LogPublisher pub2)
 {
     try
     {
         int value = int.Parse("dk20");
     }
     catch (Exception ex)
     {
         pub2.Publish(MessageLevel.Critical, "Failed Cast", null, null, ex);
     }
 }
Пример #3
0
        static ShutdownHandler()
        {
            s_syncRoot = new object();
            s_onShutdownCallbackFirst = new List<WeakAction>();
            s_onShutdownCallbackDefault = new List<WeakAction>();
            s_onShutdownCallbackLast = new List<WeakAction>();
            Logger.Initialize();
            Log = Logger.CreatePublisher(typeof(ShutdownHandler), MessageClass.Component);

            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
                AppDomain.CurrentDomain.ProcessExit += InitiateSafeShutdown;
            else
                AppDomain.CurrentDomain.DomainUnload += InitiateSafeShutdown;

        }
Пример #4
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();
        }
 /// <summary>
 /// Creates a new instance of the <see cref="SharedTimerScheduler"/> class.
 /// </summary>
 public SharedTimerScheduler()
 {
     m_syncRoot = new object();
     m_log = Logger.CreatePublisher(typeof(SharedTimerScheduler), MessageClass.Component);
     m_schedulesByInterval = new Dictionary<int, SharedTimerInstance>();
     m_reportStatus = new ScheduledTask();
     m_reportStatus.Running += ReportStatus;
     m_reportStatus.Start(60 * 1000);
 }
Пример #6
0
        // Static Constructor
        static ServiceHelper()
        {
            s_log = Logger.CreatePublisher(typeof(ServiceHelper), MessageClass.Framework);

            s_logError = s_log.RegisterEvent(MessageLevel.Error, MessageFlags.None, "Error Message", 0, MessageRate.PerSecond(30), 1000);
            s_logStatusInfo = s_log.RegisterEvent(MessageLevel.Info, MessageFlags.None, "Status Message Info", 0, MessageRate.PerSecond(30), 1000);
            s_logStatusWarning = s_log.RegisterEvent(MessageLevel.Warning, MessageFlags.None, "Status Message Warning", 0, MessageRate.PerSecond(30), 1000);
            s_logStatusAlarm = s_log.RegisterEvent(MessageLevel.Error, MessageFlags.None, "Status Message Alarm", 0, MessageRate.PerSecond(30), 1000);

            Logger.FileWriter.Verbose = VerboseLevel.Ultra;
            s_log.InitialStackTrace = LogStackTrace.Empty;
        }
Пример #7
0
 /// <summary>
 /// Creates a <see cref="DisposableLoggingClassBase"/>
 /// </summary>
 protected DisposableLoggingClassBase(MessageClass messageClassification)
 {
     Log = Logger.CreatePublisher(GetType(), messageClassification);
 }
 /// <summary>
 /// Creates a <see cref="DisposableLoggingClassBase"/>
 /// </summary>
 protected DisposableLoggingClassBase(MessageClass messageClassification)
 {
     Log = Logger.CreatePublisher(GetType(), messageClassification);
 }
Пример #9
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();
        }
Пример #10
0
        internal SharedTimer(SharedTimerScheduler scheduler, int interval = 100)
        {
            if ((object)scheduler == null)
                throw new ArgumentNullException(nameof(scheduler));

            if (scheduler.IsDisposed)
                throw new ArgumentException("Scheduler has been disposed", nameof(scheduler));

            if (interval <= 0)
                throw new ArgumentOutOfRangeException(nameof(interval));

            m_log = Logger.CreatePublisher(typeof(SharedTimerScheduler), MessageClass.Component);
            m_scheduler = scheduler;
            m_interval = interval;
            m_enabled = false;
            m_autoReset = true;
            m_callback = TimerCallback;
            m_scheduler = scheduler;
        }
Пример #11
0
 internal LogEventPublisher(LogPublisher publisher, LogEventPublisherInternal internalPublisher)
 {
     m_publisher         = publisher;
     m_internalPublisher = internalPublisher;
 }
 internal LogEventPublisher(LogPublisher publisher, LogEventPublisherInternal internalPublisher)
 {
     m_publisher = publisher;
     m_internalPublisher = internalPublisher;
 }