コード例 #1
0
        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);
        }
コード例 #2
0
        private static ILog CreateLog(
            IConfiguration configuration,
            IReloadingManager <AppSettings> settings,
            IServiceCollection services,
            CorrelationContextAccessor correlationContextAccessor)
        {
            var aggregateLogger = new AggregateLogger();
            var consoleLogger   = new LogToConsole();

            aggregateLogger.AddLog(consoleLogger);

            if (settings.CurrentValue.MarginTradingAccountManagement.UseSerilog)
            {
                aggregateLogger.AddLog(new SerilogLogger(typeof(Startup).Assembly, configuration, new List <ILogEventEnricher>
                {
                    new CorrelationLogEventEnricher("CorrelationId", correlationContextAccessor)
                }));
            }
            else if (settings.CurrentValue.MarginTradingAccountManagement.Db.StorageMode == StorageMode.SqlServer.ToString())
            {
                var sqlLogger = new LogToSql(new SqlLogRepository("AccountManagementLog",
                                                                  settings.CurrentValue.MarginTradingAccountManagement.Db.LogsConnString));

                aggregateLogger.AddLog(sqlLogger);
            }
            else if (settings.CurrentValue.MarginTradingAccountManagement.Db.StorageMode == StorageMode.Azure.ToString())
            {
                var dbLogConnectionStringManager = settings.Nested(x => x.MarginTradingAccountManagement.Db.LogsConnString);
                var dbLogConnectionString        = dbLogConnectionStringManager.CurrentValue;

                if (string.IsNullOrEmpty(dbLogConnectionString))
                {
                    consoleLogger.WriteWarningAsync(nameof(Startup), nameof(CreateLog), "Table logger is not initialized").Wait();
                    return(aggregateLogger);
                }

                if (dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))
                {
                    throw new InvalidOperationException($"LogsConnString {dbLogConnectionString} is not filled in settings");
                }

                var persistenceManager = new LykkeLogToAzureStoragePersistenceManager(
                    AzureTableStorage <Lykke.Logs.LogEntity> .Create(dbLogConnectionStringManager, "AccountManagementLog", consoleLogger),
                    consoleLogger);

                // Creating azure storage logger, which logs own messages to console log
                var azureStorageLogger = new LykkeLogToAzureStorage(persistenceManager, null, consoleLogger);

                azureStorageLogger.Start();

                aggregateLogger.AddLog(azureStorageLogger);
            }

            LogLocator.Log = aggregateLogger;

            return(aggregateLogger);
        }
コード例 #3
0
        private static ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings)
        {
            var consoleLogger   = new LogToConsole();
            var aggregateLogger = new AggregateLogger();

            aggregateLogger.AddLog(consoleLogger);

            //It is possible to run only with console logger
            if (!string.IsNullOrEmpty(settings.CurrentValue.EthereumIndexer.DB.LogsConnectionString) &&
                !string.IsNullOrEmpty(settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString))
            {
                var dbLogConnectionStringManager = settings.Nested(x => x.EthereumIndexer.DB.LogsConnectionString);
                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, "EthereumSamuraiApiLog", consoleLogger),
                    consoleLogger);

                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);

                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);
            }

            return(aggregateLogger);
        }
コード例 #4
0
        private ILog CreateLogWithSlack(IServiceCollection services, IReloadingManager <AppSettings> settings)
        {
            _console = new LogToConsole();
            var aggregateLogger = new AggregateLogger();

            aggregateLogger.AddLog(_console);

            var dbLogConnectionStringManager = settings.Nested(x => x.OrderbookToDiskWriterJob.LogsConnString);
            var dbLogConnectionString        = dbLogConnectionStringManager.CurrentValue;

            if (string.IsNullOrEmpty(dbLogConnectionString))
            {
                _console.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, "OrderbookToDiskWriterLog", _console),
                _console);

            // 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, _console);

            // Creating azure storage logger, which logs own messages to concole log
            var azureStorageLogger = new LykkeLogToAzureStorage(
                persistenceManager,
                slackNotificationsManager,
                _console);

            azureStorageLogger.Start();
            aggregateLogger.AddLog(azureStorageLogger);

            var logToSlack = LykkeLogToSlack.Create(slackService, "Bridges", LogLevel.Error | LogLevel.FatalError | LogLevel.Warning);

            aggregateLogger.AddLog(logToSlack);

            return(aggregateLogger);
        }
コード例 #5
0
        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.MtConsistencyCheckerJob.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, "ConsistencyCheckerLog", consoleLogger),
                consoleLogger);

            // Creating slack notification service, which logs own azure queue processing messages to aggregate log
            var slackService = CreateSlackService(services, settings, aggregateLogger);

            services.AddSingleton <IMtSlackNotificationsSender>(slackService);

            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);

            return(aggregateLogger);
        }
コード例 #6
0
        public async Task WriteWarningAsync(string component, string process, string context, string info, DateTime?dateTime = null)
        {
            await _consoleLog.WriteWarningAsync(component, process, context, info);

            await _tableLog.WriteWarningAsync(component, process, context, info);
        }
コード例 #7
0
        protected virtual ILog CreateLogWithSlack(IServiceCollection services,
                                                  IReloadingManager <TApplicationSettings> settings, CurrentApplicationInfo applicationInfo,
                                                  CorrelationContextAccessor correlationContextAccessor)
        {
            var logTableName    = ApplicationName + applicationInfo.EnvInfo + "Log";
            var aggregateLogger = new AggregateLogger();
            var consoleLogger   = new LogToConsole();

            aggregateLogger.AddLog(consoleLogger);

            #region Logs settings validation

            if (!settings.CurrentValue.MtBrokersLogs.UseSerilog &&
                string.IsNullOrWhiteSpace(settings.CurrentValue.MtBrokersLogs.LogsConnString))
            {
                throw new Exception("Either UseSerilog must be true or LogsConnString must be set");
            }

            #endregion Logs settings validation

            #region Slack registration

            IMtSlackNotificationsSender slackService = null;

            if (settings.CurrentValue.SlackNotifications != null)
            {
                var azureQueue = new AzureQueueSettings
                {
                    ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString,
                    QueueName        = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName
                };

                var commonSlackService =
                    services.UseSlackNotificationsSenderViaAzureQueue(azureQueue, consoleLogger);

                slackService =
                    new MtSlackNotificationsSender(commonSlackService, ApplicationName, Environment.EnvironmentName);
            }
            else
            {
                slackService =
                    new MtSlackNotificationsSenderLogStub(ApplicationName, Environment.EnvironmentName, consoleLogger);
            }

            services.AddSingleton <ISlackNotificationsSender>(slackService);
            services.AddSingleton <IMtSlackNotificationsSender>(slackService);

            #endregion Slack registration

            if (settings.CurrentValue.MtBrokersLogs.UseSerilog)
            {
                aggregateLogger.AddLog(new SerilogLogger(applicationInfo.GetType().Assembly, Configuration, new List <ILogEventEnricher>
                {
                    new CorrelationLogEventEnricher("CorrelationId", correlationContextAccessor)
                }));
            }
            else if (settings.CurrentValue.MtBrokersLogs.StorageMode == StorageMode.SqlServer)
            {
                aggregateLogger.AddLog(new LogToSql(new SqlLogRepository(logTableName,
                                                                         settings.CurrentValue.MtBrokersLogs.LogsConnString)));
            }
            else if (settings.CurrentValue.MtBrokersLogs.StorageMode == StorageMode.Azure)
            {
                var dbLogConnectionStringManager = settings.Nested(x => x.MtBrokersLogs.LogsConnString);
                var dbLogConnectionString        = dbLogConnectionStringManager.CurrentValue;

                if (string.IsNullOrEmpty(dbLogConnectionString))
                {
                    consoleLogger.WriteWarningAsync(ApplicationName,
                                                    nameof(CreateLogWithSlack), "Table logger is not initialized").Wait();
                    return(aggregateLogger);
                }

                if (dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))
                {
                    throw new InvalidOperationException($"LogsConnString {dbLogConnectionString} is not filled in settings");
                }

                // Creating azure storage logger, which logs own messages to console log
                var azureStorageLogger = services.UseLogToAzureStorage(settings.Nested(s => s.MtBrokersLogs.LogsConnString),
                                                                       slackService, logTableName, consoleLogger);

                azureStorageLogger.Start();

                aggregateLogger.AddLog(azureStorageLogger);
            }

            return(aggregateLogger);
        }