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); }
private static ILog CreateLogWithSlack(IConfiguration configuration, IServiceCollection services, IReloadingManager <AppSettings> settings, CorrelationContextAccessor correlationContextAccessor) { var consoleLogger = new LogToConsole(); var aggregateLogger = new AggregateLogger(); aggregateLogger.AddLog(consoleLogger); #region Logs settings validation if (!settings.CurrentValue.TradingHistoryService.UseSerilog && string.IsNullOrWhiteSpace(settings.CurrentValue.TradingHistoryService.Db.LogsConnString)) { throw new Exception("Either UseSerilog must be true or LogsConnString must be set"); } #endregion Logs settings validation // Creating slack notification service, which logs own azure queue processing messages to aggregate log ILykkeLogToAzureSlackNotificationsManager slackNotificationsManager = null; if (settings.CurrentValue.SlackNotifications != null) { var slackService = services.UseSlackNotificationsSenderViaAzureQueue( new Lykke.AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.CurrentValue.SlackNotifications.AzureQueue.QueueName }, aggregateLogger); slackNotificationsManager = new LykkeLogToAzureSlackNotificationsManager(slackService, consoleLogger); } if (settings.CurrentValue.TradingHistoryService.UseSerilog) { aggregateLogger.AddLog(new SerilogLogger(typeof(Startup).Assembly, configuration, new List <ILogEventEnricher>() { new CorrelationLogEventEnricher("CorrelationId", correlationContextAccessor) })); } else if (settings.CurrentValue.TradingHistoryService.Db.StorageMode == StorageMode.Azure) { var persistenceManager = new LykkeLogToAzureStoragePersistenceManager( AzureTableStorage <LogEntity> .Create(settings.Nested(x => x.TradingHistoryService.Db.LogsConnString), "TradingHistoryServiceLog", consoleLogger), consoleLogger); // Creating azure storage logger, which logs own messages to concole log var azureStorageLogger = new LykkeLogToAzureStorage( persistenceManager, slackNotificationsManager, consoleLogger); azureStorageLogger.Start(); aggregateLogger.AddLog(azureStorageLogger); } else if (settings.CurrentValue.TradingHistoryService.Db.StorageMode == StorageMode.SqlServer) { var sqlLogger = new LogToSql(new SqlLogRepository("TradingHistoryAPIsLog", settings.CurrentValue.TradingHistoryService.Db.LogsConnString)); aggregateLogger.AddLog(sqlLogger); } LogLocator.Log = aggregateLogger; return(aggregateLogger); }