Esempio n. 1
0
        public static int Main(string[] args)
        {
            // Create servicecollection with di services
            var services = new ServiceCollection()
                           .AddSingleton <Lib.Interfaces.IAppConfiguration, Lib.Services.JsonFileConfiguration>()
                           .AddSingleton <Lib.Interfaces.IInstanceService, Lib.Services.MastodonInstanceService>()
                           .AddSingleton <Lib.Interfaces.IFeedService, Lib.Services.FeedService>()
                           .AddSingleton <Lib.Interfaces.ICacheService, Lib.Services.SqliteCache.SqliteCacheService>()
                           .AddSingleton <IConsole>(PhysicalConsole.Singleton)
                           .AddLogging(log =>
            {
                // Add console logger
                log.AddConsole(c => c.IncludeScopes = true);
                log.AddSerilog();

                if (Program.Debug)
                {
                    log.SetMinimumLevel(LogLevel.Debug);
                }
            })
                           .BuildServiceProvider();

            var cfg = services.GetService <IAppConfiguration>();

            // Initialize serilog logger
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(cfg.ConfigurationRoot)
                         .Enrich.WithEnvironmentUserName()
                         .Enrich.WithMachineName()
                         .Enrich.FromLogContext()
                         .CreateLogger();

            // Create application for configuration
            var app = new CommandLineApplication <Program>();

            // configure app
            app.Conventions
            .UseDefaultConventions()
            .UseConstructorInjection(services);

            // run and return
            var result = app.Execute(args);

            services.Dispose();
            return(result);
        }