Example #1
0
        /// <summary>
        /// Logging queue processing run function
        /// </summary>
        private async Task RunLogging(CancellationToken cancelToken)
        {
            try
            {
                while (!cancelToken.IsCancellationRequested)
                {
                    await NotifyAddedLog.WaitAsync(cancelToken);

                    List <LogEventArgs> allEvents = new List <LogEventArgs>();
                    while (!LogsQueue.IsEmpty)
                    {
                        if (LogsQueue.TryDequeue(out var nextLog))
                        {
                            allEvents.AddRange(GenerateLogsForLogEvent(nextLog));
                        }
                    }

                    LoggedEvents?.Invoke(this, allEvents);

                    LogToLog4(allEvents);
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"Exception in logging: {e}.");
            }
        }
Example #2
0
        /// <summary>
        /// Process the logging queue
        /// </summary>
        void ProcessLogs()
        {
            try
            {
                //  empty the queue
                List <LogEventArgs> allEvents = new List <LogEventArgs>();
                while (!LogsQueue.IsEmpty)
                {
                    if (LogsQueue.TryDequeue(out var nextLog))
                    {
                        allEvents.AddRange(GenerateLogsForLogEvent(nextLog));
                    }
                }

                //  send event
                LoggedEvents?.Invoke(this, allEvents);

                LogToLog4(allEvents);

                //  broadcast to listeners
                foreach (var nextLog in allEvents)
                {
                    if (nextLog.Level >= LogLevelDisplay)
                    {
                        var test      = new RemoteLogEventArgs(nextLog);
                        var test2     = test.Sender.ToString();
                        var sendBytes = Encoding.UTF8.GetBytes($"log?sender={NetworkUtilities.GetHostName()}&log={JsonConvert.SerializeObject(new RemoteLogEventArgs(nextLog))}\n");
                    }

                    LogBuffer.Enqueue(nextLog);
                }

                while (LogBuffer.Count > 333)
                {
                    LogBuffer.TryDequeue(out var discard);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"Exception in logging {e}");
            }
        }