public static void Main(string[] args) { // Initialize logger var consoleLog = new LogToConsole(); var logAggregate = new LogAggregate() .AddLogger(consoleLog); var log = logAggregate.CreateLogger(); try { log.Info("Reading application settings."); var config = new ConfigurationBuilder() //.AddJsonFile("appsettings.json", optional: true) .AddEnvironmentVariables() .Build(); var settingsUrl = config.GetValue <string>("BROKER_SETTINGS_URL"); log.Info("Loading app settings from web-site."); var appSettings = LoadSettings(settingsUrl); log.Info("Initializing azure/slack logger."); var services = new ServiceCollection(); // only used for azure logger logAggregate.ConfigureAzureLogger(services, Startup.ApplicationName, appSettings); log = logAggregate.CreateLogger(); // After log is configured // log.Info("Creating Startup."); var startup = new Startup(appSettings, log); log.Info("Configure startup services."); startup.ConfigureServices(Application.Instance.ContainerBuilder, log); log.Info("Starting application."); var scope = Application.Instance.Start(); log.Info("Configure startup."); startup.Configure(scope); log.Info("Running application."); Application.Instance.Run(); log.Info("Exit application."); } catch (Exception ex) { log.WriteErrorAsync("Program", string.Empty, string.Empty, ex).Wait(); } }
private static ILog CreateLogWithSlack(IServiceCollection services, AppSettings settings) { LykkeLogToAzureStorage logToAzureStorage = null; var logToConsole = new LogToConsole(); var logAggregate = new LogAggregate(); logAggregate.AddLogger(logToConsole); var dbLogConnectionString = settings.LykkeServiceService.Db.LogsConnString; // Creating azure storage logger, which logs own messages to concole log if (!string.IsNullOrEmpty(dbLogConnectionString) && !(dbLogConnectionString.StartsWith("${") && dbLogConnectionString.EndsWith("}"))) { logToAzureStorage = new LykkeLogToAzureStorage("Lykke.Service.LykkeService", new AzureTableStorage <LogEntity>( dbLogConnectionString, "LykkeServiceLog", logToConsole)); logAggregate.AddLogger(logToAzureStorage); } // Creating aggregate log, which logs to console and to azure storage, if last one specified var log = logAggregate.CreateLogger(); // Creating slack notification service, which logs own azure queue processing messages to aggregate log var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueIntegration.AzureQueueSettings { ConnectionString = settings.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.SlackNotifications.AzureQueue.QueueName }, log); // Finally, setting slack notification for azure storage log, which will forward necessary message to slack service logToAzureStorage?.SetSlackNotification(slackService); return(log); }
private static ILog CreateLog(IServiceCollection services, ApplicationSettings settings) { var appSettings = settings.MarketProfileService; LykkeLogToAzureStorage logToAzureStorage = null; var logToConsole = new LogToConsole(); var logAggregate = new LogAggregate(); logAggregate.AddLogger(logToConsole); if (!string.IsNullOrEmpty(appSettings.Db.LogsConnectionString) && !(appSettings.Db.LogsConnectionString.StartsWith("${") && appSettings.Db.LogsConnectionString.EndsWith("}"))) { logToAzureStorage = new LykkeLogToAzureStorage("Lykke.Service.MarketProfile", new AzureTableStorage <LogEntity>( appSettings.Db.LogsConnectionString, "MarketProfileService", logToConsole)); logAggregate.AddLogger(logToAzureStorage); } var log = logAggregate.CreateLogger(); var slackService = services.UseSlackNotificationsSenderViaAzureQueue(new AzureQueueSettings { ConnectionString = settings.SlackNotifications.AzureQueue.ConnectionString, QueueName = settings.SlackNotifications.AzureQueue.QueueName }, log); logToAzureStorage?.SetSlackNotification(slackService); return(log); }
private static ILog ConfigureLog(ApplicationSettings settings, LogAggregate logAggregate, ILog log) { log.Info("Initializing azure/slack logger.", Program.Name); var services = new ServiceCollection(); // only used for azure logger logAggregate.ConfigureAzureLogger(services, Program.Name, settings); return(logAggregate.CreateLogger()); }
public static void ConfigureAzureLogger(this LogAggregate logAggregate, IServiceCollection services, string appName, AppSettings appSettings) { var log = logAggregate.CreateLogger(); var slackSender = services.UseSlackNotificationsSenderViaAzureQueue(appSettings.SlackNotifications.AzureQueue, log); var azureLog = new LykkeLogToAzureStorage(appName, new AzureTableStorage <LogEntity>(appSettings.BrokerQuoteFeed.ConnectionStrings.LogsConnectionString, appName + "Logs", log), slackSender); logAggregate.AddLogger(azureLog); }
// This method gets called by the runtime. Use this method to add services to the container public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddApplicationInsightsTelemetry(Configuration); services.AddMvc(o => { o.Filters.Add(new HandleAllExceptionsFilterFactory()); }); services.AddSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1", Title = "Api" }); options.DescribeAllEnumsAsStrings(); }); var logAggregate = new LogAggregate().AddLogger(new LogToConsole()); var log = logAggregate.CreateLogger(); var appSettings = Environment.IsEnvironment("Development") ? Configuration.Get <ApplicationSettings>() : LoadSettings(Configuration.GetValue <string>("SETTINGS_URL"), log); if (!ApplicationSettings.IsSettingsValid(appSettings, log, Program.Name)) { throw new ArgumentException(); } log = ConfigureLog(appSettings, logAggregate, log); var ioc = new ContainerBuilder(); ioc.RegisterInstance(appSettings).AsSelf(); ioc.RegisterInstance(log).As <ILog>(); ioc.RegisterInstance(new LogRepository(new AzureTableStorage <LogEntity>(appSettings.BoxOptionsApi.ConnectionStrings.BoxOptionsApiStorage, "ClientEventLogs", log))).As <ILogRepository>(); ioc.Populate(services); return(new AutofacServiceProvider(ioc.Build())); }