protected override async Task Consume(LogEntity entry)
        {
            try
            {
                if (!_logLevels.Contains(entry.Level))
                {
                    return;
                }

                var componentName = GetComponentName(entry);

                switch (entry.Level)
                {
                case LykkeLogToAzureStorage.FatalErrorType:
                {
                    var message = entry.Context != null
                            ? $"{entry.Msg} : {entry.Stack} : {entry.Context}"
                            : $"{entry.Msg} : {entry.Stack}";
                    await _slackNotificationsSender.SendErrorAsync(message, componentName);

                    break;
                }

                case LykkeLogToAzureStorage.ErrorType:
                {
                    if (await _spamGuard.ShouldBeMutedAsync(LogLevel.Error, componentName, entry.Process))
                    {
                        break;
                    }

                    var message = entry.Context != null
                            ? $"{entry.Msg} : {entry.Stack} : {entry.Context}"
                            : $"{entry.Msg} : {entry.Stack}";
                    await _slackNotificationsSender.SendErrorAsync(message, componentName);

                    break;
                }

                case LykkeLogToAzureStorage.WarningType:
                {
                    if (await _spamGuard.ShouldBeMutedAsync(LogLevel.Warning, componentName, entry.Process))
                    {
                        break;
                    }

                    var message = entry.Context != null
                            ? $"{entry.Msg} : {entry.Context}"
                            : entry.Msg;
                    await _slackNotificationsSender.SendWarningAsync(message, componentName);

                    break;
                }

                case LykkeLogToAzureStorage.MonitorType:
                {
                    if (await _spamGuard.ShouldBeMutedAsync(LogLevel.Monitoring, componentName, entry.Process))
                    {
                        break;
                    }

                    var message = entry.Context != null
                            ? $"{entry.Msg} : {entry.Context}"
                            : entry.Msg;
                    await _slackNotificationsSender.SendMonitorAsync(message, componentName);

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                await _lastResortLog.WriteErrorAsync("Send log entries to the Slack", "", ex);
            }
        }
Exemplo n.º 2
0
 public async Task ErrorAsync(string message)
 {
     await _slackNotificationsSender.SendErrorAsync(message, "bitcoin service");
 }