Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var options = _options.Value;

            while (!stoppingToken.IsCancellationRequested)
            {
                var item = await _eventQueue.DequeueAsync(stoppingToken);

                var applicationId = item.ApplicationId ?? options.CurrentApplicationId;
                var id            = await _identityGenerator.GenerateAsync();

                if (_memoryCache.TryGetValue(MonitorSettings.GetCacheKey(item.Level), out MonitorSettings settings))
                {
                    var connections = settings.GetConnections(applicationId);
                    if (connections.Any())
                    {
                        await _hubContext.Clients.Clients(connections.ToList()).ReceiveEvent(new EventViewModel
                        {
                            Id            = id,
                            Level         = item.Level.ToLower(),
                            Category      = item.Category,
                            Message       = item.Message,
                            ApplicationId = applicationId,
                            EventId       = item.EventId,
                            EventType     = item.EventType,
                            Timestamp     = item.Timestamp
                        });
                    }
                }

                var evt = new Event
                {
                    Id            = id,
                    GlobalId      = id,
                    ApplicationId = applicationId,
                    Category      = item.Category,
                    Level         = item.Level.ToLower(),
                    EventId       = item.EventId,
                    EventType     = item.EventType,
                    Message       = item.Message,
                    Exception     = item.Exception?.SerializeToJson(),
                    ProcessId     = item.ProcessId,
                    TimeStamp     = item.Timestamp
                };
                _storeQueue.Enqueue(evt);
            }
        }