Esempio n. 1
0
        public void Send(ServerSentEvent message, CancellationToken token)
        {
            lock (_syncRoot)
            {
                var closeChannels = new List<IEventChannel>();
                foreach (var channel in _channels)
                {
                    try
                    {
                        channel.Send(message, token);
                    }
                    catch (Exception)
                    {
                        closeChannels.Add(channel);
                    }
                }
                foreach (var channel in closeChannels)
                {
                    _channels.Remove(channel);
                }

                while (_replayBuffer.Count >= _replayBufferSize)
                {
                    _replayBuffer.RemoveAt(0);
                }
                _replayBuffer.Add(message);
            }
        }
Esempio n. 2
0
        public void Send(ServerSentEvent message, CancellationToken token)
        {
            lock (_syncRoot)
            {
                var closeChannels = new List <IEventChannel>();
                foreach (var channel in _channels)
                {
                    try
                    {
                        channel.Send(message, token);
                    }
                    catch (Exception)
                    {
                        closeChannels.Add(channel);
                    }
                }
                foreach (var channel in closeChannels)
                {
                    _channels.Remove(channel);
                }

                while (_replayBuffer.Count >= _replayBufferSize)
                {
                    _replayBuffer.RemoveAt(0);
                }
                _replayBuffer.Add(message);
            }
        }
 protected override void Write(LogEventInfo logEvent)
 {
     if (Active)
     {
         var message = base.Layout.Render(logEvent);
         var sse = new ServerSentEvent(logEvent.Level.Name.ToUpperInvariant(), message);
         _channel.Send(sse, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token);
     }
 }
Esempio n. 4
0
 public void Emit(LogEvent logEvent)
 {
     if (Active)
     {
         var renderSpace = new StringWriter();
         Formatter.Format(logEvent, renderSpace);
         if (LogProperties)
         {
             renderSpace.WriteLine(Environment.NewLine + string.Join(Environment.NewLine, logEvent.Properties.Select(x => "[" + x.Key + "," + x.Value + "]")));
         }
         var sse = new ServerSentEvent(MatchLevel(logEvent.Level), renderSpace.ToString());
         _channel.Send(sse, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token);
     }
 }
Esempio n. 5
0
 public void Send(ServerSentEvent sse, CancellationToken token)
 {
     Send((object)sse, token);
 }
Esempio n. 6
0
 public void Send(ServerSentEvent sse, CancellationToken token)
 {
     Send((object)sse, token);
 }
 protected override void Append(LoggingEvent loggingEvent)
 {
     var message = base.RenderLoggingEvent(loggingEvent);
     var sse = new ServerSentEvent(loggingEvent.Level.DisplayName, message);
     _channel.Send(sse, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token);
 }