Exemple #1
0
 public virtual TViewModelEntity GetViewModel(Guid id)
 {
     try
     {
         var find   = Get(id);
         var entity = _mapper.Map <TViewModelEntity>(find);
         _logger.LogInformation($"Get ID Success");
         return(entity);
     }
     catch (Exception e)
     {
         _logger.LogError($"Get Id Fail");
         throw;
     }
 }
Exemple #2
0
        public IActionResult Microsoft()
        {
            _microsoftLogger.LogTrace("Microsoft Trace");
            _microsoftLogger.LogDebug("Microsoft Debug");
            _microsoftLogger.LogInformation("Microsoft Information");
            _microsoftLogger.LogWarning("Microsoft Warning");
            _microsoftLogger.LogError("Microsoft Error");
            _microsoftLogger.LogCritical("Microsoft Critical");

            return(Ok());
        }
Exemple #3
0
        public ActionResult GetCars()
        {
            _logger.LogInformation("User requested to fetch the Cities list");
            var items = GetCarsList().ToList();

            _logger.LogInformation($"Returning {items.Count} cars as a result");
            return(Ok(items));
        }
Exemple #4
0
        public DiscordBot(
            ILogger <DiscordBot> logger,
            IEventBus eventBus,
            IOptions <DiscordConfig> configuration,
            IServiceProvider services,
            ILoggerProvider loggerProvider)
        {
            Log       = logger;
            _eventBus = eventBus;

            Services = services;

            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddProvider(loggerProvider);
                builder.SetMinimumLevel(LogLevel.Critical);
            });

            DiscordConfiguration config = new DiscordConfiguration
            {
                Token         = configuration.Value.DiscordBotKey,
                TokenType     = TokenType.Bot,
                LoggerFactory = loggerFactory
            };

            Client = new DiscordClient(config);


            Client.MessageCreated += NewMessage;
            Client.UnknownEvent   += (sender, args) =>
            {
                //logger.LogDebug("asd");
                args.Handled = true;

                return(Task.CompletedTask);
            };


            Log.LogInformation("DiscordClientConfigured");
        }
Exemple #5
0
        Task NewMessage(DiscordClient discordClient, MessageCreateEventArgs messageCreateArgs)
        {
            using (var scope = Services.CreateScope())
            {
                var dbContext = scope.ServiceProvider.GetRequiredService <CoreDatabaseContext>();

                if (messageCreateArgs.Guild != null && dbContext.GetGuildFor(messageCreateArgs.Guild.Id) is null)
                {
                    var discordGuild = messageCreateArgs.Guild;

                    Log.LogInformation("Registering guild: {GuildID}", discordGuild.Id);

                    dbContext.Add(new Guild(discordGuild.Name, discordGuild.Id.ToString()));
                    dbContext.SaveChanges();
                }

                var new_event = new DiscordMessageCreatedEvent(messageCreateArgs, dbContext);

                //_commandExecutor.ProcessMessage(new_event);
                _eventBus.PostEvent(new_event);
            }

            return(Task.CompletedTask);
        }
Exemple #6
0
        public IActionResult Index()
        {
            logger.LogInformation("Test");

            return(View());
        }