private static ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings) { var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); var dbLogConnectionStringManager = settings.Nested(x => x.DynamicJob.Db.LogsConnString); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; if (string.IsNullOrEmpty(dbLogConnectionString)) { consoleLogger.WriteWarningAsync(nameof(Startup), nameof(CreateLogWithSlack), "Table loggger is not inited").Wait(); return(aggregateLogger); } if (dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}")) { throw new InvalidOperationException($"LogsConnString {dbLogConnectionString} is not filled in settings"); } var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "DynamicJobLog", consoleLogger), consoleLogger); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); // Creating azure storage logger, which logs own messages to concole log var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); aggregateLogger.AddLog(LykkeLogToSlack.Create ( slackService, "BlockChainIntegration", LogLevel.All )); aggregateLogger.AddLog(LykkeLogToSlack.Create ( slackService, "BlockChainIntegrationImportantMessages", LogLevel.All ^ LogLevel.Info )); return(aggregateLogger); }
private ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings) { var aggregateLogger = new AggregateLogger(); var consoleLog = new LogToConsole(); aggregateLogger.AddLog(consoleLog); var dbLogConnectionStringManager = settings.Nested(x => x.TradesConverterJob.Db.LogsConnString); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; if (string.IsNullOrEmpty(dbLogConnectionString)) { consoleLog.WriteWarning(nameof(Startup), nameof(CreateLogWithSlack), "Table loggger is not inited"); return(aggregateLogger); } if (dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}")) { throw new InvalidOperationException($"LogsConnString {dbLogConnectionString} is not filled in settings"); } var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "TradesConverterLog", consoleLog), consoleLog); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager( slackService, new HashSet <string> { LykkeLogToAzureStorage.ErrorType, LykkeLogToAzureStorage.FatalErrorType, LykkeLogToAzureStorage.MonitorType }, consoleLog); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLog); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); var logToSlack = LykkeLogToSlack.Create(slackService, "Bridges", LogLevel.Error | LogLevel.FatalError | LogLevel.Warning); aggregateLogger.AddLog(logToSlack); return(aggregateLogger); }
private static ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings) { var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); var dbLogConnectionStringManager = settings.Nested(x => x.BitcoinCashApi.Db.LogsConnString); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; // Creating azure storage logger, which logs own messages to concole log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "BitcoinCashApiLog", consoleLogger), consoleLogger); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); var allMessagesSlackLogger = LykkeLogToSlack.Create ( slackService, "BlockChainIntegration", // ReSharper disable once RedundantArgumentDefaultValue LogLevel.All ); aggregateLogger.AddLog(allMessagesSlackLogger); var importantMessagesSlackLogger = LykkeLogToSlack.Create ( slackService, "BlockChainIntegrationImportantMessages", LogLevel.All ^ LogLevel.Info ); aggregateLogger.AddLog(importantMessagesSlackLogger); } return(aggregateLogger); }
public void TestLogToSlackPreventsSameMessageSpamWithDefaultConfiguration() { // Arrange string channel = "Prices"; var logToSlack = LykkeLogToSlack.Create(_slackNotificationsSenderMock, channel, disableAntiSpam: false); // Act logToSlack.WriteInfoAsync("Process", "Context", "Message").GetAwaiter().GetResult(); logToSlack.WriteInfoAsync("Process", "Context", "Message").GetAwaiter().GetResult(); //Assert _slackNotificationsSenderMock.Received().SendAsync(Arg.Is <string>(t => t == channel), Arg.Any <string>(), Arg.Any <string>()); }
private ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings) { _consoleLog = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(_consoleLog); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); var dbLogConnectionStringManager = settings.Nested(x => x.OrderbookToBlobBridgeJob.LogsConnectionString); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; // Creating azure storage logger, which logs own messages to concole log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "OrderbookToBlobBridgeLogs", _consoleLog), _consoleLog); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager( slackService, new HashSet <string> { LykkeLogToAzureStorage.ErrorType, LykkeLogToAzureStorage.FatalErrorType, LykkeLogToAzureStorage.MonitorType }, _consoleLog); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, _consoleLog); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); var logToSlack = LykkeLogToSlack.Create(slackService, "Bridges", LogLevel.Error | LogLevel.FatalError | LogLevel.Warning); aggregateLogger.AddLog(logToSlack); } return(aggregateLogger); }
private static ILog CreateLogWithSlack(IServiceCollection services, SlackNotificationsSettings slackSettings, IReloadingManager <string> dbLogConnectionStringManager) { var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueSettings { ConnectionString = slackSettings.AzureQueue.ConnectionString, QueueName = slackSettings.AzureQueue.QueueName }, aggregateLogger); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; // Creating azure storage logger, which logs own messages to concole log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "CandlesHistoryWriterLogs", consoleLogger), consoleLogger); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); } var logToSlack = LykkeLogToSlack.Create(slackService, "Prices"); aggregateLogger.AddLog(logToSlack); return(aggregateLogger); }
private static ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings) { var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); var dbLogConnectionStringManager = settings.Nested(x => x.IcoEthTransactionTrackerJob.Db.LogsConnString); var dbLogConnectionString = dbLogConnectionStringManager.CurrentValue; // Creating azure storage logger, which logs own messages to concole log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(dbLogConnectionStringManager, "IcoEthTransactionTrackerLog", consoleLogger), consoleLogger); var slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); } aggregateLogger.AddLog(LykkeLogToSlack.Create(slackService, "Ico", LogLevel.Error | LogLevel.FatalError)); return(aggregateLogger); }
private static ILog CreateLogWithSlack(IConfiguration configuration, IServiceCollection services, IReloadingManager <AppSettings> settings) { var tableName = "CandlesProducerServiceLog"; var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); LykkeLogToAzureSlackNotificationsManager slackNotificationsManager = null; if (settings.CurrentValue.SlackNotifications != null) { // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); var logToSlack = LykkeLogToSlack.Create(slackService, "Prices"); aggregateLogger.AddLog(logToSlack); } if (settings.CurrentValue.MtCandlesProducerJob.UseSerilog) { aggregateLogger.AddLog(new SerilogLogger(typeof(Startup).Assembly, configuration)); } else if (settings.CurrentValue.MtCandlesProducerJob.Db.StorageMode == StorageMode.SqlServer) { aggregateLogger.AddLog( new LogToSql(new SqlLogRepository(tableName, settings.CurrentValue.MtCandlesProducerJob.Db.LogsConnString))); } else if (settings.CurrentValue.MtCandlesProducerJob.Db.StorageMode == StorageMode.Azure) { var dbLogConnectionString = settings.CurrentValue.MtCandlesProducerJob.Db.LogsConnString; // Creating azure storage logger, which logs own messages to console log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <Logs.LogEntity> .Create(settings.Nested(x => x.MtCandlesProducerJob.Db.LogsConnString), tableName, consoleLogger), consoleLogger); var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); } } return(aggregateLogger); }