예제 #1
0
 /// <summary>
 /// Initializes a new instance of the LogTarget class
 /// </summary>
 /// <param name="minSeverity">the minimum severity of the logger</param>
 /// <param name="maxSeverity">the maximum severity of the logger</param>
 /// <param name="contextFilter">A n Expression that can be used to filter the context of provided messages</param>
 /// <param name="initialStatus">the initial status of this logger</param>
 /// <param name="debugEnabled">indicates whether to log debug-messages</param>
 protected LogTarget(int minSeverity, int maxSeverity, string contextFilter, bool initialStatus, bool debugEnabled) : this()
 {
     MinSeverity         = minSeverity;
     MaxSeverity         = maxSeverity;
     enabled             = initialStatus;
     ContextFilter       = contextFilter;
     EnableDebugMessages = debugEnabled;
     if (debugEnabled)
     {
         LogEnvironment.EnableDebugMessages();
     }
 }
예제 #2
0
        /// <summary>
        /// Dumps all events to an outputAdapter instance if one is available
        /// </summary>
        /// <param name="state"></param>
        private void DumpEvents(object?state)
        {
            try
            {
                using (var lk = globalLogCfg.PauseLogging())
                {
                    lk.Exclusive(() =>
                    {
                        using (var scope = services.CreateScope())
                        {
                            var adapter = scope.ServiceProvider.GetService <ILogOutputAdapter>();
                            if (adapter != null)
                            {
                                EnableDebugMessages = globalLogCfg.EnableDebugMessages;
                                if (EnableDebugMessages)
                                {
                                    LogEnvironment.EnableDebugMessages();
                                }
                                else
                                {
                                    LogEnvironment.DisableDebugMessages();
                                }

                                if (!events.IsEmpty)
                                {
                                    try
                                    {
                                        while (events.TryDequeue(out var eventData))
                                        {
                                            try
                                            {
                                                adapter.PopulateEvent(eventData);
                                            }
                                            catch (Exception ex)
                                            {
                                                System.Console.WriteLine(ex.OutlineException());
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        adapter.Flush();
                                    }
                                }
                            }
                            else
                            {
                                events.Clear();
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.OutlineException());
                events.Clear();
            }
            finally
            {
                if (!disposed)
                {
                    timer.Change(10000, Timeout.Infinite);
                }
            }
        }