Ejemplo n.º 1
0
        static async Task RunAsync()
        {
            Log = new LoggerConfiguration()
                  .MinimumLevel.Information()
                  .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                  .Enrich.FromLogContext()
                  .WriteTo.Async(x => x.File("logs/rift-.log", rollingInterval: RollingInterval.Day))
                  .CreateLogger();

            DiscordLogger = new LoggerConfiguration()
                            .MinimumLevel.Information()
                            .Enrich.FromLogContext()
                            .WriteTo.Async(x => x.File("logs/discord-.log", rollingInterval: RollingInterval.Day))
                            .CreateLogger();

            ChatLogger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .Enrich.FromLogContext()
                         .WriteTo.Async(x => x.File("logs/chat-.log", rollingInterval: RollingInterval.Day))
                         .CreateLogger();

            var serviceProvider = SetupServices();

            handler = new CommandHandler(serviceProvider);
            await handler.ConfigureAsync();

            try
            {
                await Task.Delay(-1, IonicHelper.GetCancellationTokenSource().Token);
            }
            catch (TaskCanceledException)
            {
                await IonicHelper.Client.StopAsync().ContinueWith(x =>
                {
                    if (!ShouldReboot)
                    {
                        Console.WriteLine("Shutting down");
                        Serilog.Log.CloseAndFlush();
                    }
                    else
                    {
                        Console.WriteLine("Restarting...");
                        Serilog.Log.CloseAndFlush();
                        Environment.Exit(4); //anything higher than zero is a restart
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex, "An error occured while shutting down");
            }
        }
Ejemplo n.º 2
0
        public async Task Shutdown()
        {
            await Context.Message.DeleteAsync();

            IonicHelper.GetCancellationTokenSource().Cancel();
        }